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

NDData show units #11553

Merged
merged 3 commits into from Apr 27, 2021
Merged

NDData show units #11553

merged 3 commits into from Apr 27, 2021

Conversation

nstarman
Copy link
Member

@nstarman nstarman commented Apr 13, 2021

Description

Now NDData with units shows the units on str() and repr(). Importantly, repr maintains its current level of fidelity to eval(repr(x)) == x (I add a check for this to the tests)

>>> x = NDData([1, 2, 3], unit="km")
>>> print(repr(x))
NDData([1, 2, 3], unit='km')

>>> print(str(x))
[1 2 3] km

@mhvk @saimn @mwcraig

Fixes #11541

Followup ideas:

  • eval(repr(x)) == x doesn't actually work for NDData, with or without units, even if they are identical attribute-by-attribute. Modding __eq__ would be good.
  • show other attributes in string representations: mask, uncertainty, ...

@pllim pllim added this to the v4.3 milestone Apr 13, 2021
@pllim pllim requested a review from mwcraig April 13, 2021 18:41
astropy/nddata/nddata.py Outdated Show resolved Hide resolved
@saimn
Copy link
Contributor

saimn commented Apr 13, 2021

👍 for me, but @mwcraig should approve as the nddata maintainer.

@nstarman nstarman force-pushed the nddata_show_units branch 2 times, most recently from fc5b382 to f68a873 Compare April 14, 2021 16:53
Signed-off-by: Nathaniel Starkman (@nstarman) <nstarkman@protonmail.com>
Signed-off-by: Nathaniel Starkman (@nstarman) <nstarkman@protonmail.com>
Signed-off-by: Nathaniel Starkman (@nstarman) <nstarkman@protonmail.com>
Copy link
Member

@mwcraig mwcraig left a comment

Choose a reason for hiding this comment

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

thanks, @nstarman, this looks great!

@mwcraig
Copy link
Member

mwcraig commented Apr 27, 2021

eval(repr(x)) == x doesn't actually work for NDData, with or without units, even if they are identical attribute-by-attribute. Modding __eq__ would be good.

I opened an issue for this at #11648

@mwcraig mwcraig merged commit 9722a1e into astropy:main Apr 27, 2021
@nstarman nstarman deleted the nddata_show_units branch April 27, 2021 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Print unit in NDData
4 participants