Skip to content

Commit 5a39fa6

Browse files
committed
DEPR: Panel deprecated
closes pandas-dev#13563
1 parent a347ecb commit 5a39fa6

File tree

11 files changed

+2825
-2592
lines changed

11 files changed

+2825
-2592
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

@@ -284,6 +285,33 @@ Using ``.iloc``. Here we will get the location of the 'A' column, then use *posi
284285
df.iloc[[0, 2], df.columns.get_loc('A')]
285286

286287

288+
.. _whatsnew_0200.api_breaking.deprecate_panel:
289+
290+
Deprecate Panel
291+
^^^^^^^^^^^^^^^
292+
293+
- The ``Panel`` constructor is deprecated and will be removed in a future version. The recommended way to represent 3-D data are
294+
with a ``MultiIndex``on a ``DataFrame`` via the :meth:`~Panel.to_frame` or with the `xarray package <http://xarray.pydata.org/en/stable/>`__. Pandas
295+
provides a :meth:`~Panel.to_xarray` method to automate this conversion (:issue:`13563`).
296+
297+
.. ipython:: python
298+
:okwarning:
299+
300+
p = tm.makePanel()
301+
p
302+
303+
Convert to a MultiIndex DataFrame
304+
305+
.. ipython:: python
306+
307+
p.frame()
308+
309+
Convert to an xarray DataArray
310+
311+
.. ipython:: python
312+
313+
p.to_xarray()
314+
287315
.. _whatsnew.api_breaking.io_compat
288316

289317
Possible incompat for HDF5 formats for pandas < 0.13.0

pandas/core/categorical.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -563,8 +563,8 @@ def _validate_categories(cls, categories, fastpath=False):
563563
# we don't allow NaNs in the categories themselves
564564

565565
if categories.hasnans:
566-
# NaNs in cats deprecated in 0.17,
567-
# remove in 0.18 or 0.19 GH 10748
566+
# NaNs in cats deprecated in 0.17
567+
# GH 10748
568568
msg = ('\nSetting NaNs in `categories` is deprecated and '
569569
'will be removed in a future version of pandas.')
570570
warn(msg, FutureWarning, stacklevel=3)

pandas/core/panel.py

+12
Original file line numberDiff line numberDiff line change
@@ -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+
FutureWarning, 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

pandas/io/pytables.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -2096,7 +2096,17 @@ def convert(self, values, nan_rep, encoding):
20962096

20972097
# we have a categorical
20982098
categories = self.metadata
2099-
self.data = Categorical.from_codes(self.data.ravel(),
2099+
codes = self.data.ravel()
2100+
2101+
# if we have stored a NaN in the categories
2102+
# then strip it; in theory we could have BOTH
2103+
# -1s in the codes and nulls :<
2104+
mask = isnull(categories)
2105+
if mask.any():
2106+
categories = categories[~mask]
2107+
codes[codes != -1] -= mask.astype(int).cumsum().values
2108+
2109+
self.data = Categorical.from_codes(codes,
21002110
categories=categories,
21012111
ordered=self.ordered)
21022112

@@ -3406,10 +3416,12 @@ def create_axes(self, axes, obj, validate=True, nan_rep=None,
34063416
if existing_table is not None:
34073417
indexer = len(self.non_index_axes)
34083418
exist_axis = existing_table.non_index_axes[indexer][1]
3409-
if append_axis != exist_axis:
3419+
if not array_equivalent(np.array(append_axis),
3420+
np.array(exist_axis)):
34103421

34113422
# ahah! -> reindex
3412-
if sorted(append_axis) == sorted(exist_axis):
3423+
if array_equivalent(np.array(sorted(append_axis)),
3424+
np.array(sorted(exist_axis))):
34133425
append_axis = exist_axis
34143426

34153427
# the non_index_axes info

0 commit comments

Comments
 (0)