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

AxisArrays.axisnames should instead extend Base.names? #155

Open
nickrobinson251 opened this issue Jan 9, 2019 · 3 comments
Open

AxisArrays.axisnames should instead extend Base.names? #155

nickrobinson251 opened this issue Jan 9, 2019 · 3 comments

Comments

@nickrobinson251
Copy link

nickrobinson251 commented Jan 9, 2019

I had expected names to work i.e.

julia> using AxisArrays

julia> A = AxisArray(reshape(1:15, 5, 3), Axis{:time}(.1:.1:0.5), Axis{:col}([:a, :b, :c]))
5×3 AxisArray{Int64,2,Base.ReshapedArray{Int64,2,UnitRange{Int64},Tuple{}},Tuple{Axis{:time,StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}},Axis{:col,Array{Symbol,1}}}}:
 1   6  11
 2   7  12
 3   8  13
 4   9  14
 5  10  15

julia> names(A)
# (:time, :col)

julia> names(A.axes)
# (:time, :col)

julia> names(A.axes[1])
# :time

but these all give MethodErrors -- I instead need to use AxisArrays.axisnames(A) and AxisArrays.axisname(A.axes[1]) (and there is no AxisArrays.axisnames(A.axes)).

The precedent for extending Base.names comes from DataFrames.jl e.g.

julia> using DataFrames

julia> df = DataFrame(a = 1:5, b = 6:10)
5×2 DataFrame
│ Row │ a     │ b     │
│     │ Int64 │ Int64 │
├─────┼───────┼───────┤
│ 116     │
│ 227     │
│ 338     │
│ 449     │
│ 5510    │

julia> names(df)
2-element Array{Symbol,1}:
 :a
 :b
@iamed2
Copy link
Collaborator

iamed2 commented Jan 9, 2019

I think that fits with #152

@c42f
Copy link
Member

c42f commented Feb 11, 2019

So rather than names we'd use propertynames I suppose. (Side note: I'm not sure why Base even has the distinction between names and propertynames, given that access to module bindings goes through getproperty. Might be an oversight.)

@nickrobinson251
Copy link
Author

nickrobinson251 commented Aug 16, 2019

The more i think about this, the less keen I am on it. I think axisnames is a fine name.

Although I do wish it had the behaviour I mentioned.

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

No branches or pull requests

3 participants