Skip to content

3D DataArray.to_pandas() fails with a bad message #3835

Closed
@max-sixty

Description

@max-sixty

Panel is removed from pandas (as a result of the success of xarray! 😁 ), but we're still attempting to call it from .to_pandas()

MCVE Code Sample

# Your code here
In [4]: import numpy as np                                                                                                                                          

In [1]: import xarray as xr   
In [5]: xr.DataArray(np.random.rand(2,3,4)).to_pandas()                                                                                                             
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-5-7d1b667d5cac> in <module>
----> 1 xr.DataArray(np.random.rand(2,3,4)).to_pandas()

~/workspace/corpfin/.venv/lib64/python3.6/site-packages/xarray/core/dataarray.py in to_pandas(self)
   2267             )
   2268         indexes = [self.get_index(dim) for dim in self.dims]
-> 2269         return constructor(self.values, *indexes)
   2270 
   2271     def to_dataframe(self, name: Hashable = None) -> pd.DataFrame:

TypeError: object() takes no parameters

Expected Output

Either a MultiIndexed DataFrame or a proper error (4D gives ValueError: cannot convert arrays with 4 dimensions into pandas objects)

Output of xr.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 3.7.3 | packaged by conda-forge | (default, Jul 1 2019, 21:52:21) [GCC 7.3.0] python-bits: 64 OS: Linux OS-release: ... machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_US.utf8 LOCALE: en_US.UTF-8 libhdf5: 1.10.5 libnetcdf: 4.7.1 xarray: 0.15.0 pandas: 1.0.1 numpy: 1.17.3 scipy: 1.3.2 netCDF4: 1.5.3 pydap: None h5netcdf: 0.7.4 h5py: 2.10.0 Nio: None zarr: None cftime: 1.0.4.2 nc_time_axis: None PseudoNetCDF: None rasterio: None cfgrib: None iris: None bottleneck: 1.2.1 dask: 2.7.0 distributed: 2.7.0 matplotlib: 3.1.2 cartopy: None seaborn: 0.9.0 numbagg: installed setuptools: 41.6.0.post20191101 pip: 19.3.1 conda: None pytest: 5.2.2 IPython: 7.9.0 sphinx: 2.2.1

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