Skip to content

Array value assignment via .values and .data fails with Pandas 3.0.0 (assignment destination is read-only) #11133

@tomvothecoder

Description

@tomvothecoder

What happened?

With Pandas 3.0.0, value assignment through DataArray.values and DataArray.data now fails with: ValueError: assignment destination is read-only

This appears to be due to the underlying NumPy array having its WRITEABLE flag set to False with Pandas 3.0. This affects common mutation patterns used in Xarray workflows, even when working with simple in-memory datasets.

The MVCE works with Pandas 2.x, but breaks with Pandas 3.0.0.

  • Pandas 2.x environment: conda create -n xr_pd2 -c conda-forge xarray netcdf4 "pandas<3.0.0" ipykernel
  • Pandas 3.0.0 environment: conda create -n xr_pd3 -c conda-forge xarray netcdf4 "pandas>=3.0.0" ipykernel

What did you expect to happen?

I expected value assignment via .values and .data to continue working consistently across Pandas 2.x and 3.x.

Minimal Complete Verifiable Example

# /// script
# requires-python = ">=3.11"
# dependencies = [
#   "xarray[complete]@git+https://github.com/pydata/xarray.git@main",
# ]
# ///
#
# 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
xr.show_versions()

import numpy as np

# Create a dummy xarray dataset
ds = xr.Dataset(
    {
        "lon": ("lon", [180, 359, 0, 1, 179, 0]),
        "lon_bnds": (("lon", "bnds"), np.random.rand(6, 2)),
    }
)

# .values[] -> ValueError: assignment destination is read-only
ds["lon"].values[-1] = 360

# .data[] -> ValueError: assignment destination is read-only
ds["lon"].data[-1] = 360

arr = ds["lon"].values
print(arr.flags["WRITEABLE"])
# False

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

Anything else we need to know?

No response

Environment

Details >>> xr.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.14.2 | packaged by conda-forge | (main, Jan 26 2026, 20:19:28) [Clang 20.1.8 ]
python-bits: 64
OS: Darwin
OS-release: 24.6.0
machine: arm64
processor: arm
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: ('en_US', 'UTF-8')
libhdf5: 1.14.6
libnetcdf: 4.9.3

xarray: 2026.1.0
pandas: 3.0.0
numpy: 2.4.2
scipy: None
netCDF4: 1.7.4
pydap: None
h5netcdf: None
h5py: None
zarr: None
cftime: 1.6.5
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: 26.0
conda: None
pytest: None
mypy: None
IPython: 9.10.0
sphinx: None

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions