-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
What happened?
I was attempting to save a dataset to a netcdf to a memoryview so I could write it to a BytesIO object and upload it to AWS S3. Upon calling ds.to_netcdf(None) I got a BufferError.
What did you expect to happen?
I expected a memoryview object to be returned which I could then input into a BytesIO object.
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
import xarray as xr
xr.show_versions()
# your reproducer code ...
with open("./tim.0100.nc", "rb") as originalFile:
with xr.load_dataset(originalFile) as ds:
example = ds.to_netcdf(
path=None,
)Steps to reproduce
You can find the files here: https://noaa-wsa-enlil-pds.s3.amazonaws.com/index.html#wsa_enlil.20250922_57558/wsa_enlil_57558.67133207.dbqs01/
I setup a venv with python 3.12 and installed the following from a requirements.txt file:
netcdf4
numpy
scipy
xarray
importlib-metadata==4.13.0
I also ran a pip freeze after and this is what it contained:
certifi==2025.8.3
cftime==1.6.4.post1
importlib-metadata==4.13.0
netCDF4==1.7.2
numpy==2.3.3
packaging==25.0
pandas==2.3.2
python-dateutil==2.9.0.post0
pytz==2025.2
scipy==1.16.2
six==1.17.0
tzdata==2025.2
xarray==2025.9.0
zipp==3.23.0
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
Exception ignored in: <function netcdf_file.close at 0x7f285663fd80>
Traceback (most recent call last):
File "/var/lang/lib/python3.12/site-packages/scipy/io/_netcdf.py", line 320, in close
self.fp.close()
BufferError: Existing exports of data: object cannot be re-sizedAnything else we need to know?
No response
Environment
INSTALLED VERSIONS
commit: None
python: 3.12.10 (main, Jul 9 2025, 16:46:51) [Clang 17.0.0 (clang-1700.0.13.5)]
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.4
libnetcdf: 4.9.2
xarray: 2025.9.0
pandas: 2.3.2
numpy: 2.3.3
scipy: 1.16.2
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: 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.0.1
conda: None
pytest: None
mypy: None
IPython: None
sphinx: None