Skip to content

Saving and reloading DataArray from NetCDF breaks comparison of NaN attributes #10833

@zyjux

Description

@zyjux

What happened?

I have a workflow in which we combine a number of datasets from different satellites using xr.concat and use combine_attrs="drop_conflicts" to preserve attributes that are in common while dropping those that differ, like platform name, etc. One of the attributes for a number of the DataArrays inside the datasets is a fill value parameter, which for our scalar arrays is np.nan. Up until recently, this was concatenating these datasets and combining attributes properly, including the fill values. However, we recently updated to 2025.9.1 and started getting errors in our integration tests that the fill values were being dropped rather than combined. After doing some testing, I was able to recreate the issue in the MVCE below using just DataArrays (rather than Datasets, where we first noticed the issue) by writing the arrays to netCDF and reading them back into memory.

What did you expect to happen?

I was not expecting passing through netCDF to change the comparison behavior of NaNs, and would hope that it would behave similarly to if the arrays had been in memory the whole time.

Minimal Complete Verifiable Example

import numpy as np
import xarray as xr

xr.show_versions()

print("\n----------------\n")

# Set up dummy arrays to concatenate, with matching nan attribute
array_A = xr.DataArray(
    np.zeros((5,)),
    dims="x",
    attrs={"fill_value": np.nan, "sensor": "G18", "field": "CTH"},
)
array_B = xr.DataArray(
    np.ones((5,)),
    dims="x",
    attrs={"fill_value": np.nan, "sensor": "G16", "field": "CTH"},
)

# Concatenate arrays using "drop_conflicts" to handle attributes
merged_array = xr.concat(
    [array_A, array_B],
    dim="y",
    combine_attrs="drop_conflicts",
)

# Print merged array attributes
print("In memory array attributes:")
print(merged_array.attrs)

# Now save arrays to netcdf and reload
array_A.to_netcdf("ds_A.nc")
array_A = xr.load_dataarray("ds_A.nc")

array_B.to_netcdf("ds_B.nc")
array_B = xr.load_dataarray("ds_B.nc")

# Again concatenate arrays in the same way
merged_array = xr.concat(
    [array_A, array_B],
    dim="y",
    combine_attrs="drop_conflicts",
)

# Print merged array attributes
print("Loaded from NetCDF array attributes:")
print(merged_array.attrs)

Steps to reproduce

No response

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

In memory array attributes:
{'fill_value': nan, 'field': 'CTH'}
Loaded from NetCDF array attributes:
{'field': 'CTH'}

Anything else we need to know?

No response

Environment

Details

INSTALLED VERSIONS

commit: None
python: 3.14.0 | packaged by conda-forge | (main, Oct 7 2025, 20:07:29) [GCC 14.3.0]
python-bits: 64
OS: Linux
OS-release: 5.14.0-427.16.1.el9_4.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: ('en_US', 'UTF-8')
libhdf5: 1.14.6
libnetcdf: 4.9.3

xarray: 2025.10.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
nc_time_axis: None
iris: None
bottleneck: None
dask: None
distributed: None
matplotlib: None
cartopy: None
seaborn: None
numbagg: None
fsspec: None
cupy: None
pint: None
sparse: None
flox: None
numpy_groupies: None
setuptools: None
pip: 25.2
conda: None
pytest: None
mypy: None
IPython: None
sphinx: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions