Skip to content

Commit

Permalink
DEPR: Panel deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
jreback committed Mar 25, 2017
1 parent fca80ef commit 99b5694
Show file tree
Hide file tree
Showing 10 changed files with 2,711 additions and 2,423 deletions.
8 changes: 8 additions & 0 deletions doc/source/dsintro.rst
Expand Up @@ -763,6 +763,14 @@ completion mechanism so they can be tab-completed:
Panel
-----

.. warning::

In 0.20.0, ``Panel`` is deprecated and will be removed in
a future version. The recommended way to represent 3-D data are
with a ``MultiIndex``on a ``DataFrame`` via the :meth:`~Panel.to_frame` or
with the `xarray package <http://xarray.pydata.org/en/stable/>`__. Pandas
provides a :meth:`~Panel.to_xarray` method to automate this conversion.

Panel is a somewhat less-used, but still important container for 3-dimensional
data. The term `panel data <http://en.wikipedia.org/wiki/Panel_data>`__ is
derived from econometrics and is partially responsible for the name pandas:
Expand Down
28 changes: 28 additions & 0 deletions doc/source/whatsnew/v0.20.0.txt
Expand Up @@ -11,6 +11,7 @@ Highlights include:

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


.. _whatsnew_0200.api_breaking.deprecate_panel:

Deprecate Panel
^^^^^^^^^^^^^^^

``Panel`` is deprecated and will be removed in a future version. The recommended way to represent 3-D data are
with a ``MultiIndex``on a ``DataFrame`` via the :meth:`~Panel.to_frame` or with the `xarray package <http://xarray.pydata.org/en/stable/>`__. Pandas
provides a :meth:`~Panel.to_xarray` method to automate this conversion (:issue:`13563`).

.. ipython:: python
:okwarning:

p = tm.makePanel()
p

Convert to a MultiIndex DataFrame

.. ipython:: python

p.frame()

Convert to an xarray DataArray

.. ipython:: python

p.to_xarray()

.. _whatsnew.api_breaking.io_compat:

Possible incompat for HDF5 formats for pandas < 0.13.0
Expand Down
14 changes: 13 additions & 1 deletion pandas/core/panel.py
Expand Up @@ -5,7 +5,7 @@
from __future__ import division

import numpy as np

import warnings
from pandas.types.cast import (infer_dtype_from_scalar,
maybe_cast_item)
from pandas.types.common import (is_integer, is_list_like,
Expand Down Expand Up @@ -130,6 +130,18 @@ def _constructor(self):

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

self._init_data(data=data, items=items, major_axis=major_axis,
minor_axis=minor_axis, copy=copy, dtype=dtype)

Expand Down

0 comments on commit 99b5694

Please sign in to comment.