Skip to content

Remove most warning exclusions#10695

Merged
max-sixty merged 16 commits into
pydata:mainfrom
max-sixty:warnings-cleanup-2
Sep 4, 2025
Merged

Remove most warning exclusions#10695
max-sixty merged 16 commits into
pydata:mainfrom
max-sixty:warnings-cleanup-2

Conversation

@max-sixty
Copy link
Copy Markdown
Collaborator

Summary

Removed the global warning filter for non-tuple sequence indexing by fixing the underlying code.

Changes

  • Fixed deprecated numpy indexing in test_nputils.py that was using x[[1, 2], [1, 2]]
  • Changed to proper tuple indexing: x[([1, 2], [1, 2])]
  • Removed the warning exclusion from pyproject.toml

This continues the work from #10693 to clean up warning exclusions.

🤖 Generated with Claude Code

max-sixty and others added 16 commits September 3, 2025 15:08
Removed 11 warning exclusions that are no longer needed:
- Invalid cast warnings from duck_array_ops and test_array_api
- CachingFileManager deallocation warnings from backends
- Deprecated treenode methods (ancestors, iter_lineage, lineage)
- Test-specific deprecations that no longer exist

These exclusions were verified to be safe to remove through testing.
The test suite passes with 20,779 tests after removal.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Removed 3 more warning exclusions that are no longer needed:
- UserWarning from test_coding_times
- UserWarning from test_computation
- UserWarning from test_dataset

All test files pass without these warning exclusions.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Removed warning exclusions that are no longer needed:
- "No index created" UserWarning - Tests properly handle with pytest.warns
- "pandas.MultiIndex" FutureWarning - No longer triggered
- "Duplicate dimension names" UserWarning - Tests handle with local filterwarnings

These warnings are either properly tested or no longer occur.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Fixed test_dataset.py to use pytest.warns instead of warnings.catch_warnings
for testing the interpolation->method deprecation warning. This makes it
consistent with the other test files.

Note: We cannot remove the global warning exclusion because the error:::xarray.*
rule converts warnings to errors before pytest.warns can catch them. This is
a known limitation of the current filterwarnings configuration.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Instead of relying on a global warning exclusion, added
@pytest.mark.filterwarnings decorators to the specific tests that
test the interpolation->method deprecation warning. This allows
the warning to be properly tested while avoiding the conflict
with the error:::xarray.* rule.

Now the global exclusion for this warning can be safely removed.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Fixed the test in test_nputils.py that was using deprecated list indexing
x[[1, 2], [1, 2]] by changing it to tuple indexing x[([1, 2], [1, 2])].

This allows us to remove the global warning filter for 'Using a non-tuple
sequence for multidimensional indexing is deprecated'.
Removed the following warning exclusions from pyproject.toml:
- 'Failed to decode variable.*NumPy will stop allowing conversion...'
- 'NumPy will stop allowing conversion of:DeprecationWarning'

These exclusions are no longer needed as the tests pass without them.
The remaining 'invalid value encountered in cast' warnings are legitimate
and occur when casting NaN values to integer types.
These warnings are no longer ignored and will be reported in CI.

Co-authored-by: Claude <no-reply@anthropic.com>
Fixed tests to properly handle the expected RuntimeWarning when casting
NaN values to integer types:

- Updated test_conventions.py::test_missing_fillvalue to explicitly catch
  both the SerializationWarning and the numpy RuntimeWarning
- Added create_nan_array() helper function in test_units.py that suppresses
  the cast warning when creating test arrays with NaN values for int dtypes
- Removed the two warning exclusions from pyproject.toml

These warnings were legitimate - they occur when casting float arrays
containing NaN to integer types, which is expected behavior in these
test scenarios.
Handle overflow when casting _FillValue to dtype in CFMaskCoder.encode().
This fixes CI failures on older NumPy versions where casting 255 to int8
raises a DeprecationWarning (newer NumPy raises OverflowError).

The fix:
- Wraps the dtype.type(fv) call in a try/except block
- Suppresses the NumPy DeprecationWarning for older versions
- Catches OverflowError for newer NumPy versions
- Uses np.array(fv).astype(dtype) which properly wraps the value
Added comprehensive handling for NumPy's DeprecationWarning about
out-of-bound integer conversion in multiple locations:

- Added _safe_type_cast() helper function to handle the conversion safely
- Updated _encode_unsigned_fill_value() to suppress the warning
- Fixed missing_value encoding to use _safe_type_cast()
- Refactored _FillValue encoding to use the helper function

This should fix all test failures in the bare-min-and-scipy CI environment
where older NumPy versions raise DeprecationWarning instead of OverflowError.
Replaced complex warning suppression with a simpler, more consistent approach:
- _safe_type_cast() now uses np.array(value).astype(dtype).item() which works
  consistently across NumPy 1.x and 2.x for overflow cases
- _encode_unsigned_fill_value() now explicitly checks bounds using np.iinfo()
  before attempting the cast, making the logic clearer
- This removes unnecessary try/except blocks and warning filters

The root issue: NumPy changed behavior between versions:
- NumPy 1.x: dtype.type(out_of_bounds) raises DeprecationWarning but succeeds
- NumPy 2.x: dtype.type(out_of_bounds) raises OverflowError

The test itself (test_roundtrip_unsigned) is correctly testing edge cases
where unsigned values (255) need to be stored as signed int8, which is a
legitimate use case in CF conventions for unsigned integer encoding.
- Added handle_numpy_1_warnings autouse fixture to conftest.py
- Removes need for workarounds in the actual code
- Handles NumPy version differences cleanly at the test level
- Reverted variables.py to simpler implementation without _safe_type_cast
@max-sixty max-sixty changed the title Remove non-tuple sequence indexing warning exclusion Remove most warning exclusions Sep 4, 2025
@max-sixty max-sixty enabled auto-merge (squash) September 4, 2025 02:31
@max-sixty max-sixty merged commit de6d87d into pydata:main Sep 4, 2025
35 of 36 checks passed
@max-sixty max-sixty deleted the warnings-cleanup-2 branch September 4, 2025 02:42
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.

1 participant