AxisArrays.jl icon indicating copy to clipboard operation
AxisArrays.jl copied to clipboard

AxisArrays.axisnames should instead extend Base.names?

Open nickrobinson251 opened this issue 6 years ago • 3 comments
trafficstars

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

nickrobinson251 avatar Jan 09 '19 17:01 nickrobinson251

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

iamed2 avatar Jan 09 '19 19:01 iamed2

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.)

c42f avatar Feb 11 '19 00:02 c42f

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.

nickrobinson251 avatar Aug 16 '19 09:08 nickrobinson251