masked Quantity fails on astropy master with numpy 1.17.2
See original GitHub issueMasked Quantity
started failing with astropy
master and numpy 1.17.2
:
>>> import numpy as np
>>> import astropy.units as u
>>> masked_quantity = np.ma.array([1, 2, 3 ,4] * u.kg,
... mask=[True, False, True, False])
>>> print(masked_quantity)
Traceback (most recent call last):
File "/Users/lbradley/Dropbox/softw/packages/dev/astropy/astropy/units/quantity.py", line 1319, in _to_own_unit
_value = value.to_value(self.unit)
AttributeError: '_MaskedPrintOption' object has no attribute 'to_value'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "./ma.py", line 8, in <module>
print(masked_quantity)
File "/Users/lbradley/local/conda/envs/dev/lib/python3.7/site-packages/numpy/ma/core.py", line 3870, in __str__
return str(self._insert_masked_print())
File "/Users/lbradley/local/conda/envs/dev/lib/python3.7/site-packages/numpy/ma/core.py", line 3864, in _insert_masked_print
_recursive_printoption(res, mask, masked_print_option)
File "/Users/lbradley/local/conda/envs/dev/lib/python3.7/site-packages/numpy/ma/core.py", line 2443, in _recursive_printoption
np.copyto(result, printopt, where=mask)
File "<__array_function__ internals>", line 6, in copyto
File "/Users/lbradley/Dropbox/softw/packages/dev/astropy/astropy/units/quantity.py", line 1475, in __array_function__
args, kwargs, unit, out = function_helper(*args, **kwargs)
File "/Users/lbradley/Dropbox/softw/packages/dev/astropy/astropy/units/quantity_helper/function_helpers.py", line 270, in copyto
return ((dst.view(np.ndarray), dst._to_own_unit(src)) + args,
File "/Users/lbradley/Dropbox/softw/packages/dev/astropy/astropy/units/quantity.py", line 1324, in _to_own_unit
as_quantity = Quantity(value)
File "/Users/lbradley/Dropbox/softw/packages/dev/astropy/astropy/units/quantity.py", line 374, in __new__
raise TypeError("The value must be a valid Python or "
TypeError: The value must be a valid Python or Numpy numeric type.
It works fine with astropy
master and numpy <= 1.17.1
. It also works fine with astropy 3.2.1
and numpy = 1.17.2
:
>>> import numpy as np
>>> import astropy.units as u
>>> masked_quantity = np.ma.array([1, 2, 3 ,4] * u.kg,
... mask=[True, False, True, False])
>>> print(masked_quantity)
[-- 2.0 -- 4.0] kg
Ping: @mhvk
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Masked Values (astropy.utils.masked) — Astropy v5.2
Astropy Masked instances behave like ndarray or subclasses such as Quantity but with a mask associated, which is propagated in operations such as...
Read more >Release Notes — NumPy v1.17 Manual
This release contains a number of fixes for bugs reported against NumPy 1.17.0 along with a few documentation and build improvements. The Python...
Read more >Release 1.1.dev0 Henry Leung
Calculate mean absolute error, ignoring the magic number ... mask (np.ndarray) – numpy boolean array as a mask for incoming tensor. Returns.
Read more >xinyu7030/numpy - Gitiles
+* `#13950 <https://github.com/numpy/numpy/pull/13950>`__: Fixing failure on Python 2.7 on Windows 7 +* `#13952 ... REL: Update master after 1.17.2 release.
Read more >Astropy complaining about Numpy version - python
I had a bad Numpy installation. The solution was to repeatedly uninstall Numpy, as regular user and root, until no more installations were ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
well, for one units do not propagate correctly… It is a long-standing wish list to have it work, but almost certainly we need to make our own masked type…
Yes, there is, and that would certainly help (but might take a while…)