Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

diag(::DataFrame)? #2268

Closed
anandijain opened this issue May 22, 2020 · 2 comments
Closed

diag(::DataFrame)? #2268

anandijain opened this issue May 22, 2020 · 2 comments
Labels

Comments

@anandijain
Copy link
Contributor

The diag function from LinearAlgebra is pretty handy. It may just be extra clutter to have in DataFrames, but it isn't hard to write and I can think of a few cases where it'd be nice to have (heatmaps, etc).

I think that diag(::DataFrame) can be written st you can @assert diag(df, n) == diag(Matrix(df), n) so it wouldn't pollute the namespace as much as if it returned a different type.

Thoughts?

@bkamins
Copy link
Member

bkamins commented May 22, 2020

I am not sure it would be useful. DataFrame is not a matrix and I think it is easy enough to write e.g. what you have written in practice.

A different pattern would be getindex.(Ref(df), axes(df)...) which should be much more efficient for large data frames.

@anandijain
Copy link
Contributor Author

getindex. and axes is a nice pattern, although it doesn't work on non-square dfs.

this is what i wrote to solve that

min_axes = minimum(axes(df))
getindex.(Ref(df), (min_axes, min_axes...)

also what would be the nice way to write diag using the shift argument:

  julia> A = [1 2 3; 4 5 6; 7 8 9]
  3×3 Array{Int64,2}:
   1  2  3
   4  5  6
   7  8  9

  julia> diag(A,1)
  2-element Array{Int64,1}:
   2
   6

Overall, I think I agree that a separate diag() doesn't need to be written, and was mainly looking for the efficient pattern.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants