Skip to content

Commit f8e8d97

Browse files
committed
DEPR: Panel deprecated
closes pandas-dev#13563
1 parent 59759ce commit f8e8d97

File tree

10 files changed

+2712
-2427
lines changed

10 files changed

+2712
-2427
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

+29-1
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ users upgrade to this version.
1010
Highlights include:
1111

1212
- The ``.ix`` indexer has been deprecated, see :ref:`here <whatsnew_0200.api_breaking.deprecate_ix>`
13+
- ``Panel`` has been deprecated, see :ref:`here <whatsnew_0200.api_breaking.deprecate_panel>`
1314
- Improved user API when accessing levels in ``.groupby()``, see :ref:`here <whatsnew_0200.enhancements.groupby_access>`
1415
- Improved support for UInt64 dtypes, see :ref:`here <whatsnew_0200.enhancements.uint64_support>`
15-
- Window Binary Corr/Cov operations return a MultiIndex DataFrame rather than a Panel, see :ref:`here <whhatsnew_0200.api_breaking.rolling_pairwise>`
1616
- A new orient for JSON serialization, ``orient='table'``, that uses the Table Schema spec, see :ref:`here <whatsnew_0200.enhancements.table_schema>`
17+
- Window Binary Corr/Cov operations return a MultiIndex DataFrame rather than a Panel, see :ref:`here <whhatsnew_0200.api_breaking.rolling_pairwise>`
1718
- Support for S3 handling now uses ``s3fs``, see :ref:`here <whatsnew_0200.api_breaking.s3>`
1819
- Google BigQuery support now uses the ``pandas-gbq`` library, see :ref:`here <whatsnew_0200.api_breaking.gbq>`
1920
- Switched the test framework to use `pytest <http://doc.pytest.org/en/latest>`__ (:issue:`13097`)
@@ -425,6 +426,33 @@ Using ``.iloc``. Here we will get the location of the 'A' column, then use *posi
425426
df.iloc[[0, 2], df.columns.get_loc('A')]
426427

427428

429+
.. _whatsnew_0200.api_breaking.deprecate_panel:
430+
431+
Deprecate Panel
432+
^^^^^^^^^^^^^^^
433+
434+
``Panel`` is deprecated and will be removed in a future version. The recommended way to represent 3-D data are
435+
with a ``MultiIndex``on a ``DataFrame`` via the :meth:`~Panel.to_frame` or with the `xarray package <http://xarray.pydata.org/en/stable/>`__. Pandas
436+
provides a :meth:`~Panel.to_xarray` method to automate this conversion (:issue:`13563`).
437+
438+
.. ipython:: python
439+
:okwarning:
440+
441+
p = tm.makePanel()
442+
p
443+
444+
Convert to a MultiIndex DataFrame
445+
446+
.. ipython:: python
447+
448+
p.frame()
449+
450+
Convert to an xarray DataArray
451+
452+
.. ipython:: python
453+
454+
p.to_xarray()
455+
428456
.. _whatsnew.api_breaking.io_compat:
429457

430458
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)