Skip to content

Conversation

@valeriupredoi
Copy link
Collaborator

@valeriupredoi valeriupredoi commented Jan 6, 2026

Description

In numpy=2.4.0 a one-element np.ndarray missing_value is not accepted anymore once the fill_value is a float, and tosses a ValueError: setting an element with a sequence, and as of numpy/numpy#29421 and numpy/numpy#29423 it only accepts floats and strings. This comes from a now-enforced Deprecation that allows only 0-dim arrays to be converted to scalars:

TypeError: only 0-dimensional arrays can be converted to Python scalars

See numpy/numpy#30591

The MRE I posted at numpy:

import numpy as np


# works fine
missing_value = 33.
data = np.ma.array(
    [[[-900., 33.], [33., -900], [33., 44.]]],
    mask=False,
    fill_value=-900.0,
    dtype=float
)
s = np.ma.masked_equal(data, missing_value)
print(s)

# fails only with numpy=2.4.0
missing_value = np.array([33.], dtype=float)
data = np.ma.array(
    [[[-900., 33.], [33., -900], [33., 44.]]],
    mask=False,
    fill_value=-900.0,
    dtype=float
)
s = np.ma.masked_equal(data, missing_value)
print(s)

Before you get started

Checklist

  • This pull request has a descriptive title and labels
  • This pull request has a minimal description (most was discussed in the issue, but a two-liner description is still desirable)
  • Unit tests have been added (if codecov test fails)
  • All tests pass

@valeriupredoi valeriupredoi added the bug Something isn't working label Jan 6, 2026
@codecov
Copy link

codecov bot commented Jan 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.04%. Comparing base (c8e7d8a) to head (531ff1c).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #303      +/-   ##
==========================================
+ Coverage   86.00%   86.04%   +0.04%     
==========================================
  Files           7        7              
  Lines         643      645       +2     
==========================================
+ Hits          553      555       +2     
  Misses         90       90              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@valeriupredoi valeriupredoi merged commit 451bab2 into main Jan 7, 2026
4 of 5 checks passed
@davidhassell
Copy link
Collaborator

Hang on! Only just reviewing this now ....

The missing_value attribute int the file can be a vector of two or more numbers, so well need to deal with this case to allow for the possibility of multiple setting of data = np.ma.masked_equal(data, missing_value)

@valeriupredoi
Copy link
Collaborator Author

@davidhassell ah snap, sorry! Let me open a PR with that fix, I thought the missing value is always a single float

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants