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

implement Axis.astype #880

Closed
gdementen opened this issue Aug 4, 2020 · 1 comment
Closed

implement Axis.astype #880

gdementen opened this issue Aug 4, 2020 · 1 comment

Comments

@gdementen
Copy link
Contributor

I relatively often need to change an axis labels dtype. For example to convert labels to int64, I currently have to do:

>>> arr = ndtest("a=1..3")
>>> arr.a.dtype
dtype('int32')
>>> arr.set_labels('a', arr.a.labels.astype(np.int64))
>>> # this would be a tad shorter and makes sense IMO
... arr.set_labels('a', arr.a.astype(np.int64))

In an ideal world, arr.set_labels('a', np.int64) would work too (but I am unsure it is possible). It currently returns an object array for the axis labels:

>>> arr.set_labels('a', np.int64).a.dtype
dtype('O')
@gdementen
Copy link
Contributor Author

Here is a more realistic example: convert "string" labels to integers

>>> arr = zeros('a=2000,2001,total').drop('total')
>>> arr.a
Axis(['2000', '2001'], 'a')
>>> arr.set_labels('a', int).a
Axis([2000, 2001], 'a')
>>> arr.set_labels('a', int).a.dtype
dtype('O')

@alixdamman alixdamman self-assigned this Aug 26, 2020
@alixdamman alixdamman added this to the 0.33 milestone Aug 28, 2020
alixdamman added a commit to alixdamman/larray that referenced this issue Aug 28, 2020
alixdamman added a commit to alixdamman/larray that referenced this issue Feb 24, 2021
alixdamman added a commit to alixdamman/larray that referenced this issue Feb 24, 2021
gdementen pushed a commit to gdementen/larray that referenced this issue Nov 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants