JuliaArrays / AxisArrays.jl

Performant arrays where each dimension can have a named axis with values
http://JuliaArrays.github.io/AxisArrays.jl/latest/
Other
200 stars 41 forks source link

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

Open nickrobinson251 opened 5 years ago

nickrobinson251 commented 5 years ago

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 │
├─────┼───────┼───────┤
│ 1   │ 1     │ 6     │
│ 2   │ 2     │ 7     │
│ 3   │ 3     │ 8     │
│ 4   │ 4     │ 9     │
│ 5   │ 5     │ 10    │

julia> names(df)
2-element Array{Symbol,1}:
 :a
 :b
iamed2 commented 5 years ago

I think that fits with https://github.com/JuliaArrays/AxisArrays.jl/pull/152

c42f commented 5 years ago

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 commented 5 years ago

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.