Skip to content

AttributeError: 'PandasIndex' object has no attribute 'dtype' #6880

@muwizayeon

Description

@muwizayeon

What is your issue?

Hi, all

I tried to load the xarray.Dataset that was saved a couple of months ago by using dill as follows:

with open(rslt_path + snio_fname, "rb") as inputf:
    ppsp_snios = dill.load(inputf)

The problem is that I got an attribute error AttributeError: 'PandasIndex' object has no attribute 'dtype' after I updated the xarray version 2022.6.0. when I did ppsp_snios.keys() and cannot use for further calculation. However, I can access this after I downgraded to version 0.19.0. Can anyone have any suggestions to solve this problem?

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
File ~/miniconda3/envs/pymc/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 ~/miniconda3/envs/pymc/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 ~/miniconda3/envs/pymc/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 ~/miniconda3/envs/pymc/lib/python3.10/_collections_abc.py:864, in MappingView.__repr__(self)
    863 def __repr__(self):
--> 864     return '{0.__class__.__name__}({0._mapping!r})'.format(self)

File ~/miniconda3/envs/pymc/lib/python3.10/site-packages/xarray/core/dataset.py:2077, in Dataset.__repr__(self)
   2076 def __repr__(self) -> str:
-> 2077     return formatting.dataset_repr(self)

File ~/miniconda3/envs/pymc/lib/python3.10/site-packages/xarray/core/formatting.py:611, in dataset_repr(ds)
    608 summary.append(f"{dims_start}({dims_values})")
    610 if ds.coords:
--> 611     summary.append(coords_repr(ds.coords, col_width=col_width, max_rows=max_rows))
    613 unindexed_dims_str = unindexed_dims_repr(ds.dims, ds.coords, max_rows=max_rows)
    614 if unindexed_dims_str:

File ~/miniconda3/envs/pymc/lib/python3.10/site-packages/xarray/core/formatting.py:400, in coords_repr(coords, col_width, max_rows)
    398 if col_width is None:
    399     col_width = _calculate_col_width(coords)
--> 400 return _mapping_repr(
    401     coords,
    402     title="Coordinates",
    403     summarizer=summarize_variable,
    404     expand_option_name="display_expand_coords",
    405     col_width=col_width,
    406     indexes=coords.xindexes,
    407     max_rows=max_rows,
    408 )

File ~/miniconda3/envs/pymc/lib/python3.10/site-packages/xarray/core/formatting.py:372, in _mapping_repr(mapping, title, summarizer, expand_option_name, col_width, max_rows, indexes)
    367             summary += [
    368                 summarizer(k, mapping[k], col_width, **summarizer_kwargs[k])
    369                 for k in keys[-last_rows:]
    370             ]
    371     else:
--> 372         summary += [
    373             summarizer(k, v, col_width, **summarizer_kwargs[k])
    374             for k, v in mapping.items()
    375         ]
    376 else:
    377     summary += [EMPTY_REPR]

File ~/miniconda3/envs/pymc/lib/python3.10/site-packages/xarray/core/formatting.py:373, in <listcomp>(.0)
    367             summary += [
    368                 summarizer(k, mapping[k], col_width, **summarizer_kwargs[k])
    369                 for k in keys[-last_rows:]
    370             ]
    371     else:
    372         summary += [
--> 373             summarizer(k, v, col_width, **summarizer_kwargs[k])
    374             for k, v in mapping.items()
    375         ]
    376 else:
    377     summary += [EMPTY_REPR]

File ~/miniconda3/envs/pymc/lib/python3.10/site-packages/xarray/core/formatting.py:306, in summarize_variable(name, var, col_width, max_width, is_index)
    304 else:
    305     dims_str = ""
--> 306 front_str = f"{first_col}{dims_str}{variable.dtype} "
    308 values_width = max_width - len(front_str)
    309 values_str = inline_variable_array_repr(variable, values_width)

File ~/miniconda3/envs/pymc/lib/python3.10/site-packages/xarray/core/variable.py:330, in Variable.dtype(self)
    328 @property
    329 def dtype(self):
--> 330     return self._data.dtype

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions