You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using file-like (with open(filename...) in connection with ds.sortby() we get TypeError: cannot pickle 'BufferedReader' instances. ds.reindex() works.
What did you expect to happen?
ds.sortby should work without error.
Minimal Complete Verifiable Example
The issue is triggered by ds.sortby(), we can strip this down to pure xarray:
importnumpyasnpimportnetCDF4importxarrayasxrimportfsspecimportio# create file with netCDF4 to have all bits and piecesfilename="test.h5"withnetCDF4.Dataset(filename,'w') asf:
f.createDimension('x', 3)
f.createDimension('y', 6)
var=f.createVariable('var', 'int8', ('x', 'y'))
xcoord=f.createVariable('x', 'int8', ('x'))
ycoord=f.createVariable('y', 'int8', ('y'))
xcoord[:] = [2, 1, 0]
ycoord[:] = [0, 1, 2, 3, 4, 5]
var[:] =np.arange(18).reshape((3, 6))
This works, maybe because CachingFileManager ist used?
It must have to do how the Aligner-object is initialized.
One difference between sortby and reindex is that the latter uses given indexes and join="inner" whereas sortby only uses join="left". That leads to a deepcopy inside _reindex_callback (Line 3517) which finally tries to pickle the underlying BufferedReader instance:
What happened?
When using file-like (
with open(filename...
) in connection withds.sortby()
we getTypeError: cannot pickle 'BufferedReader' instances
.ds.reindex()
works.What did you expect to happen?
ds.sortby
should work without error.Minimal Complete Verifiable Example
The issue is triggered by
ds.sortby()
, we can strip this down to pure xarray:This works, maybe because
CachingFileManager
ist used?This works too, with
reindex
.This breaks with sortby.
MVCE confirmation
Relevant log output
Anything else we need to know?
There are quite a bunch of GH issues out there, which are discussing that problem. It seems, that io.BufferedReader can't be pickled.
XRef:
What I'm wondering is why the reindex above works and the sortby fails?
Environment
xarray: 2024.7.1.dev12+gb22c4296.d20240809
pandas: 2.2.2
numpy: 2.0.1
scipy: 1.14.0
netCDF4: 1.7.1
pydap: None
h5netcdf: 1.3.0
h5py: 3.11.0
zarr: None
cftime: 1.6.4
nc_time_axis: None
iris: None
bottleneck: 1.4.0
dask: 2024.8.0
distributed: 2024.8.0
matplotlib: 3.8.4
cartopy: 0.23.0
seaborn: None
numbagg: None
fsspec: 2024.6.1
cupy: None
pint: 0.24.3
sparse: None
flox: None
numpy_groupies: None
setuptools: 70.1.1
pip: 24.0
conda: None
pytest: 8.2.2
mypy: None
IPython: 8.25.0
sphinx: None
The text was updated successfully, but these errors were encountered: