Skip to content

xr.core.utils.equivalent no longer correctly compares np.float32('nan') values #10805

@alfredoahds

Description

@alfredoahds

What happened?

xarray.core.utils.equivalent now returns False when both input values are numpy.float32('nan'), previous versions (2025.09.0 and earlier) return True. This behavior is consistent across the set of numpy.float dtypes.

This issue was identified when a previously working test that uses xr.testing.assert_identical on datasets with a numpy.float32(nan) nodata value in the attrs started failing after a version upgrade.

What did you expect to happen?

xarray.core.utils.equivalent(numpy.float32('nan'), numpy.float32('nan')) should return True.

Minimal Complete Verifiable Example

# /// script
# requires-python = ">=3.11"
# dependencies = [
#   "xarray>=2025.09.1",
# ]
# ///
#
# This script automatically imports the development branch of xarray to check for issues.
# Please delete this header if you have _not_ tested this script with `uv run`!

import xarray as xr
import numpy as np


xr.show_versions()

from xarray.core.utils import equivalent

assert equivalent(np.float32("nan"), np.float32("nan")), "Numpy-dtyped nan values should be equivalent"
assert equivalent(np.float64("nan"), np.float64("nan")), "Numpy-dtyped nan values should be equivalent"

Steps to reproduce

uv run ... the MVCE snippet above to reproduce the issue.

MVCE confirmation

  • Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
  • Complete example — the example is self-contained, including all data and the text of any traceback.
  • Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
  • New issue — a search of GitHub Issues suggests this is not a duplicate.
  • Recent environment — the issue occurs with the latest version of xarray and its dependencies.

Relevant log output

Anything else we need to know?

No response

Environment

INSTALLED VERSIONS

commit: None
python: 3.11.12 (main, May 22 2025, 01:59:30) [Clang 20.1.4 ]
python-bits: 64
OS: Linux
OS-release: 5.15.167.4-microsoft-standard-WSL2
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: C.UTF-8
LOCALE: ('en_US', 'UTF-8')
libhdf5: 1.14.2
libnetcdf: 4.9.4-development

xarray: 2025.9.1
pandas: 2.3.3
numpy: 2.3.3
scipy: None
netCDF4: 1.7.2
pydap: None
h5netcdf: None
h5py: None
zarr: None
cftime: 1.6.4.post1
nc_time_axis: None
iris: None
bottleneck: None
dask: 2025.9.1
distributed: 2025.9.1
matplotlib: 3.10.5
cartopy: None
seaborn: None
numbagg: None
fsspec: 2025.9.0
cupy: None
pint: None
sparse: None
flox: None
numpy_groupies: None
setuptools: 80.9.0
pip: None
conda: None
pytest: 8.4.1
mypy: None
IPython: 9.6.0
sphinx: 8.1.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugneeds triageIssue that has not been reviewed by xarray team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions