question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Masked ``_array2string`` doesn't work on some structured arrays

See original GitHub issue

Description

The dispatch function _array2string in masked.function_helpers doesn’t work on arrays with strutcured dtypes.

Expected behavior

Masked arrays with structured dtypes can be printed no prob, like their non-masked counterparts.

Actual behavior

It errors because of the structured dtype.

Steps to Reproduce

Here’s an example:

from astropy.utils.masked import Masked
from astropy.uncertainty import Distribution

arr = np.array(Distribution(((np.random.beta(2,5, 10000)-(2/7))/2 + 3)))  # just for convenience.
x = Masked(arr, mask=False)

repr(x)

While the following works:

repr(arr)

System Details

macOS-10.16-x86_64-i386-64bit Python 3.9.12 (main, Jun 1 2022, 06:36:29) [Clang 12.0.0 ] Numpy 1.22.3 pyerfa 2.0.0.1 astropy 5.2.dev131+ga2da0589eb.d20220607 Scipy 1.8.1 Matplotlib 3.5.2

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
mhvkcommented, Jun 27, 2022

Fix in #13404!

0reactions
mhvkcommented, Jun 27, 2022

The problem is the array-valued field. It is clear I never tested that…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Strange Error when adding 2 numpy masked arrays
This isn't a masked array issue; it's a string dtype one. In [254]: a = np.arange(4) In [255]: a Out[255]: array([0, 1, 2,...
Read more >
structured arrays slow to mask · Issue #17850 - GitHub
Fitting the data into one (n, 5) array works, and masking is equally fast with a (5, n) array. I'd love to use...
Read more >
NumPy 1.14.0 Release Notes
In short, it is now the case that, when changing a view of a masked array, ... If you experience an unexpected import...
Read more >
Numpy manual contents
Numpy manual contents¶ · Ones and zeros · numpy.empty · numpy.empty_like · From existing data · numpy.array · numpy.asarray · Creating record arrays...
Read more >
Source code for numpy.ma.core - Astropy
OverflowError is seldom used, and the real problem here is # that the passed ... a : structured array Returns ------- output :...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found