home / github / issues

Menu
  • GraphQL API
  • Search all tables

issues: 1372053736

This data as json

id node_id number title user state locked assignee milestone comments created_at updated_at closed_at author_association active_lock_reason draft pull_request body reactions performed_via_github_app state_reason repo type
1372053736 I_kwDOAMm_X85Rx-Do 7032 DataArray saved from v0.19.0 is faulty when reading with v0.21.0+ 13188417 closed 0     2 2022-09-13T22:04:55Z 2022-09-14T01:29:41Z 2022-09-14T01:29:41Z NONE      

What happened?

I have two different machines one of which is a bit older and is used for large-scale computation. I used xarray 0.19.0 there to save the dataarray using pickle (to_netctdf didn't work for my case). The data is then loaded on a machine with a newer version of xarray. When this loaded DataArray is used wierd things happen:

Reading data.coords results in an error:

AttributeError: 'PandasIndex' object has no attribute 'shape'

A similar error appears when using data.sel(...).

What did you expect to happen?

No response

Minimal Complete Verifiable Example

```Python

No verifiable example since the error occurs when using my data

import pickle data = pickle.load(open('data.pkl', 'rb')) print(data.coords) ```

MVCE confirmation

  • [X] Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
  • [X] 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.
  • [X] New issue — a search of GitHub Issues suggests this is not a duplicate.

Relevant log output

```Python

AttributeError Traceback (most recent call last) File ~/.local/lib/python3.10/site-packages/IPython/core/formatters.py:707, in PlainTextFormatter.call(self, obj) 700 stream = StringIO() 701 printer = pretty.RepresentationPrinter(stream, self.verbose, 702 self.max_width, self.newline, 703 max_seq_length=self.max_seq_length, 704 singleton_pprinters=self.singleton_printers, 705 type_pprinters=self.type_printers, 706 deferred_pprinters=self.deferred_printers) --> 707 printer.pretty(obj) 708 printer.flush() 709 return stream.getvalue()

File ~/.local/lib/python3.10/site-packages/IPython/lib/pretty.py:410, in RepresentationPrinter.pretty(self, obj) 407 return meth(obj, self, cycle) 408 if cls is not object \ 409 and callable(cls.dict.get('repr')): --> 410 return _repr_pprint(obj, self, cycle) 412 return _default_pprint(obj, self, cycle) 413 finally:

File ~/.local/lib/python3.10/site-packages/IPython/lib/pretty.py:778, in repr_pprint(obj, p, cycle) 776 """A pprint that just redirects to the normal repr function.""" 777 # Find newlines and replace them with p.break() --> 778 output = repr(obj) 779 lines = output.splitlines() 780 with p.group():

File ~/.local/lib/python3.10/site-packages/xarray/core/coordinates.py:79, in Coordinates.repr(self) 78 def repr(self) -> str: ---> 79 return formatting.coords_repr(self)

File ~/.local/lib/python3.10/site-packages/xarray/core/formatting.py:431, in coords_repr(coords, col_width, max_rows) 429 def coords_repr(coords, col_width=None, max_rows=None): 430 if col_width is None: --> 431 col_width = _calculate_col_width(_get_col_items(coords)) 432 return _mapping_repr( 433 coords, 434 title="Coordinates", (...) 438 max_rows=max_rows, 439 )

File ~/.local/lib/python3.10/site-packages/xarray/core/formatting.py:373, in _get_col_items(mapping) 371 var = getattr(v, "variable", v) 372 if isinstance(var, IndexVariable): --> 373 level_names = var.to_index_variable().level_names 374 if level_names is not None: 375 col_items += list(level_names)

File ~/.local/lib/python3.10/site-packages/xarray/core/variable.py:2806, in IndexVariable.level_names(self) 2801 @property 2802 def level_names(self): 2803 """Return MultiIndex level names or None if this IndexVariable has no 2804 MultiIndex. 2805 """ -> 2806 index = self.to_index() 2807 if isinstance(index, pd.MultiIndex): 2808 return index.names

File ~/.local/lib/python3.10/site-packages/xarray/core/variable.py:2787, in IndexVariable.to_index(self) 2784 """Convert this variable to a pandas.Index""" 2785 # n.b. creating a new pandas.Index from an old pandas.Index is 2786 # basically free as pandas.Index objects are immutable -> 2787 assert self.ndim == 1 2788 index = self._data.array 2789 if isinstance(index, pd.MultiIndex): 2790 # set default names for multi-index unnamed levels so that 2791 # we can safely rename dimension / coordinate later

File ~/.local/lib/python3.10/site-packages/xarray/core/utils.py:559, in NdimSizeLenMixin.ndim(self) 557 @property 558 def ndim(self: Any) -> int: --> 559 return len(self.shape)

File ~/.local/lib/python3.10/site-packages/xarray/core/variable.py:317, in Variable.shape(self) 315 @property 316 def shape(self): --> 317 return self._data.shape

AttributeError: 'PandasIndex' object has no attribute 'shape' ```

Anything else we need to know?

No response

Environment

INSTALLED VERSIONS ------------------ commit: None python: 3.10.4 (main, Apr 2 2022, 09:04:19) [GCC 11.2.0] python-bits: 64 OS: Linux OS-release: 5.10.102.1-microsoft-standard-WSL2 machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: C.UTF-8 LOCALE: ('en_US', 'UTF-8') libhdf5: None libnetcdf: None xarray: 0.21.0 pandas: 1.3.4 numpy: 1.21.5 scipy: 1.8.0 netCDF4: None pydap: None h5netcdf: None h5py: None Nio: None zarr: None cftime: None nc_time_axis: None PseudoNetCDF: None rasterio: None cfgrib: None iris: None bottleneck: None dask: None distributed: None matplotlib: 3.5.2 cartopy: None seaborn: 0.11.2 numbagg: None fsspec: None cupy: 10.4.0 pint: None sparse: None setuptools: 59.6.0 pip: 22.1 conda: None pytest: 6.2.5 IPython: 8.3.0 sphinx: 4.5.0
{
    "url": "https://api.github.com/repos/pydata/xarray/issues/7032/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  completed 13221727 issue

Links from other tables

  • 2 rows from issues_id in issues_labels
  • 2 rows from issue in issue_comments
Powered by Datasette · Queries took 0.563ms · About: xarray-datasette