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

setname! doesn't allow Symbol as a name #141

Open
injun6 opened this issue Dec 16, 2024 · 1 comment
Open

setname! doesn't allow Symbol as a name #141

injun6 opened this issue Dec 16, 2024 · 1 comment

Comments

@injun6
Copy link

injun6 commented Dec 16, 2024

setname! function doesn't allow the name with Symbol format

For example,

a = NamedArray(zeros((3, 3)))
setnames!(a, ["a", "b", "c"], 1)

works well with following result:

3×3 Named Matrix{Float64}
A ╲ B │   1    2    3
──────┼──────────────
a     │ 0.0  0.0  0.0
b     │ 0.0  0.0  0.0
c     │ 0.0  0.0  0.0

However, for the index name with Symbol format like below:

a = NamedArray(zeros((3, 3)))
setnames!(a, [:a, :b, :c], d=1)

returns following error:

ERROR: TypeError: in setnames!, in second argument, expected String, got Type{Symbol}
Stacktrace:
 [1] setnames!(n::NamedMatrix{Float64, Matrix{…}, Tuple{…}}, v::Vector{Symbol}, d::Int64)
   @ NamedArrays C:\Users\aa\.julia\packages\NamedArrays\e4HMa\src\names.jl:99
 [2] top-level scope
   @ c:\research\ABM_julia\0_10_0.jl:191
Some type information was truncated. Use `show(err)` to see complete types.

Any plans to update the problem?

@davidavdav
Copy link
Owner

This is intentional. The type of a has Strings as index type. Setting the index to a Symbol is a type violation.

You can initialize a different NamedArray with Symbols` as index.

a = NamedArray(a, ([:a, :b, :c], [:a, :b, :c]))

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

2 participants