Skip to content

Commit 044a255

Browse files
committed
DEPR: Panel deprecated
closes pandas-dev#13563
1 parent 9c2153b commit 044a255

File tree

10 files changed

+2711
-2426
lines changed

10 files changed

+2711
-2426
lines changed

doc/source/dsintro.rst

+8
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,14 @@ completion mechanism so they can be tab-completed:
763763
Panel
764764
-----
765765

766+
.. warning::
767+
768+
In 0.20.0, ``Panel`` is deprecated and will be removed in
769+
a future version. The recommended way to represent 3-D data are
770+
with a ``MultiIndex``on a ``DataFrame`` via the :meth:`~Panel.to_frame` or
771+
with the `xarray package <http://xarray.pydata.org/en/stable/>`__. Pandas
772+
provides a :meth:`~Panel.to_xarray` method to automate this conversion.
773+
766774
Panel is a somewhat less-used, but still important container for 3-dimensional
767775
data. The term `panel data <http://en.wikipedia.org/wiki/Panel_data>`__ is
768776
derived from econometrics and is partially responsible for the name pandas:

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>`
@@ -372,6 +373,33 @@ Using ``.iloc``. Here we will get the location of the 'A' column, then use *posi
372373
df.iloc[[0, 2], df.columns.get_loc('A')]
373374

374375

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

377405
Possible incompat for HDF5 formats for pandas < 0.13.0

pandas/core/panel.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import warnings
88

99
import numpy as np
10-
10+
import warnings
1111
from pandas.types.cast import (infer_dtype_from_scalar,
1212
maybe_cast_item)
1313
from pandas.types.common import (is_integer, is_list_like,
@@ -132,6 +132,18 @@ def _constructor(self):
132132

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

0 commit comments

Comments
 (0)