Skip to content

Keep attrs in call to astype #2070

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

Closed
wants to merge 1 commit into from
Closed

Conversation

gajomi
Copy link
Contributor

@gajomi gajomi commented Apr 21, 2018

self.data = duck_array_ops.astype(self.data,
dtype,
casting = casting,
copy = copy)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E251 unexpected spaces around keyword / parameter equals

Copy link
Member

@shoyer shoyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @gajomi!

@@ -1458,6 +1458,10 @@ def test_array_interface(self):
bar = Variable(['x', 'y'], np.zeros((10, 20)))
assert_equal(self.dv, np.maximum(self.dv, bar))

def test_astype_attrs(self):
mda = self.mda.astype(bool)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to test the datatype converting behavior of astype() here, too, at least with a few minimal cases. I don't know if we have test coverage for this already.

@dcherian
Copy link
Contributor

dcherian commented Dec 7, 2018

Hey @gajomi, do you have time to pick this back up? Looks like it just needs a few small changes.

@max-sixty
Copy link
Collaborator

If anyone would like to pick this up (@gajomi if you're still around!), please do; it's very close and would be a welcome addition

@gajomi
Copy link
Contributor Author

gajomi commented Feb 14, 2020

Oh my... It's been some time since I have logged in to github... I will have to take a look at this over the weekend to see if I can remember where I was on this PR

@dnowacki-usgs
Copy link
Contributor

Just ran into this issue.

If it's really just a matter of expanding tests and resolving conflicts of @gajomi's PR to the current codebase I can take this on, but I don't want to take their credit. Is there an easy way for a non-owner to modify a PR or should I submit a new one?

@gajomi
Copy link
Contributor Author

gajomi commented Aug 3, 2020

Hi @dnowacki-usgs. Feel free to take all the credit! I have ended up swamped at work the last few months and just haven't had the time to get back into this yet. I am guessing easiest way to move forward would be to fork my last commit and open up a new pull request.

dnowacki-usgs added a commit to dnowacki-usgs/xarray that referenced this pull request Aug 3, 2020
dnowacki-usgs added a commit to dnowacki-usgs/xarray that referenced this pull request Aug 5, 2020
dnowacki-usgs added a commit to dnowacki-usgs/xarray that referenced this pull request Aug 6, 2020
dnowacki-usgs added a commit to dnowacki-usgs/xarray that referenced this pull request Aug 13, 2020
dnowacki-usgs added a commit to dnowacki-usgs/xarray that referenced this pull request Aug 13, 2020
dnowacki-usgs added a commit to dnowacki-usgs/xarray that referenced this pull request Aug 19, 2020
dcherian pushed a commit that referenced this pull request Aug 19, 2020
* Recreate @gajomi's #2070 to keep attrs when calling astype()

* Accept keep_attrs flag, use apply_ufunc in variable.py, expand tests

* Ignore casting if we get a TypeError (indicates sparse <= 0.10.0)

* add to whats new

* fix dtype test

* improve error handling and check if sparse array

* test and docstring updates

* catch sparse error a bit more elegantly

* check using sparse_array_type

Co-authored-by: Keewis <[email protected]>
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

Successfully merging this pull request may close these issues.

Keeping attributes when using DataArray.astype
6 participants