Skip to content

Commit e716b3a

Browse files
committed
DEPR: Panel deprecated
closes pandas-dev#13563
1 parent 0ee6303 commit e716b3a

File tree

9 files changed

+2735
-2452
lines changed

9 files changed

+2735
-2452
lines changed

doc/source/whatsnew/v0.20.0.txt

+28
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Highlights include:
1111

1212
- Building pandas for development now requires ``cython >= 0.23`` (:issue:`14831`)
1313
- The ``.ix`` indexer has been deprecated, see :ref:`here <whatsnew_0200.api_breaking.deprecate_ix>`
14+
- ``Panel`` has been deprecated, see :ref:`here <whatsnew_0200.api_breaking.deprecate_panel>`
1415
- Switched the test framework to `pytest`_ (:issue:`13097`)
1516
- A new orient for JSON serialization, ``orient='table'``, that uses the Table Schema spec, see :ref:`here <whatsnew_0200.enhancements.table_schema>`
1617
- Window Binary Corr/Cov operations return a MultiIndex DataFrame rather than a Panel, see :ref:`here <whhatsnew_0200.api_breaking.rolling_pairwise>`
@@ -367,6 +368,33 @@ Using ``.iloc``. Here we will get the location of the 'A' column, then use *posi
367368
df.iloc[[0, 2], df.columns.get_loc('A')]
368369

369370

371+
.. _whatsnew_0200.api_breaking.deprecate_panel:
372+
373+
Deprecate Panel
374+
^^^^^^^^^^^^^^^
375+
376+
- The ``Panel`` constructor is deprecated and will be removed in a future version. The recommended way to represent 3-D data are
377+
with a ``MultiIndex``on a ``DataFrame`` via the :meth:`~Panel.to_frame` or with the `xarray package <http://xarray.pydata.org/en/stable/>`__. Pandas
378+
provides a :meth:`~Panel.to_xarray` method to automate this conversion (:issue:`13563`).
379+
380+
.. ipython:: python
381+
:okwarning:
382+
383+
p = tm.makePanel()
384+
p
385+
386+
Convert to a MultiIndex DataFrame
387+
388+
.. ipython:: python
389+
390+
p.frame()
391+
392+
Convert to an xarray DataArray
393+
394+
.. ipython:: python
395+
396+
p.to_xarray()
397+
370398
.. _whatsnew.api_breaking.io_compat:
371399

372400
Possible incompat for HDF5 formats for pandas < 0.13.0

pandas/core/panel.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from __future__ import division
66

77
import numpy as np
8-
8+
import warnings
99
from pandas.types.cast import (infer_dtype_from_scalar,
1010
maybe_cast_item)
1111
from pandas.types.common import (is_integer, is_list_like,
@@ -130,6 +130,18 @@ def _constructor(self):
130130

131131
def __init__(self, data=None, items=None, major_axis=None, minor_axis=None,
132132
copy=False, dtype=None):
133+
# deprecation GH13563
134+
warnings.warn("\nPanel is deprecated and will be removed in a "
135+
"future version.\nThe recommended way to represent "
136+
"these types of 3-dimensional data are with a "
137+
"MultiIndex on a DataFrame, via the "
138+
"Panel.to_frame() method\n"
139+
"alternatively, you can use the `xarray package "
140+
"<http://xarray.pydata.org/en/stable/>`__.\n"
141+
"Pandas provides a `.to_xarray()` method to help "
142+
"automate this conversion.\n",
143+
DeprecationWarning, stacklevel=3)
144+
133145
self._init_data(data=data, items=items, major_axis=major_axis,
134146
minor_axis=minor_axis, copy=copy, dtype=dtype)
135147

0 commit comments

Comments
 (0)