Skip to content

Commit 3f55809

Browse files
committed
DEPR: Panel4d and panelND
closes pandas-dev#13564
1 parent 4dd734c commit 3f55809

File tree

17 files changed

+992
-1043
lines changed

17 files changed

+992
-1043
lines changed

doc/source/dsintro.rst

+8
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,10 @@ method:
941941
Panel4D (Experimental)
942942
----------------------
943943

944+
.. warning::
945+
946+
In 0.19.0 ``Panel4D` is deprecated and will be removed in a future version. The recommended way to represent these types of n-dimensional data are with the `xarray package <http://xarray.pydata.org/en/stable/>`__. Pandas provides a :meth:`~Panel4D.to_xarray` method to automate this conversion.
947+
944948
``Panel4D`` is a 4-Dimensional named container very much like a ``Panel``, but
945949
having 4 named dimensions. It is intended as a test bed for more N-Dimensional named
946950
containers.
@@ -1026,6 +1030,10 @@ copy by default unless the data are heterogeneous):
10261030
PanelND (Experimental)
10271031
----------------------
10281032

1033+
.. warning::
1034+
1035+
In 0.19.0 ``PanelND` is deprecated and will be removed in a future version. The recommended way to represent these types of n-dimensional data are with the `xarray package <http://xarray.pydata.org/en/stable/>`__.
1036+
10291037
PanelND is a module with a set of factory functions to enable a user to construct N-dimensional named
10301038
containers like Panel4D, with a custom set of axis labels. Thus a domain-specific container can easily be
10311039
created.

doc/source/whatsnew/v0.19.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ Deprecations
613613
- ``Timestamp.offset`` property (and named arg in the constructor), has been deprecated in favor of ``freq`` (:issue:`12160`)
614614
- ``pd.tseries.util.pivot_annual`` is deprecated. Use ``pivot_table`` as alternative, an example is :ref:`here <cookbook.pivot>` (:issue:`736`)
615615
- ``pd.tseries.util.isleapyear`` has been deprecated and will be removed in a subsequent release. Datetime-likes now have a ``.is_leap_year`` property. (:issue:`13727`)
616-
616+
- ``Panel4D`` and ``PanelND`` constructors are deprecated and will be removed in a future version. The recommended way to represent these types of n-dimensional data are with the `xarray package <http://xarray.pydata.org/en/stable/>`__. Pandas provides a :meth:`~Panel4D.to_xarray` method to automate this conversion. (:issue:`13564`)
617617

618618
.. _whatsnew_0190.prior_deprecations:
619619

pandas/api/tests/test_api.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,10 @@ class TestPDApi(Base, tm.TestCase):
5858

5959
# these are already deprecated; awaiting removal
6060
deprecated_classes = ['SparsePanel', 'TimeSeries', 'WidePanel',
61-
'SparseTimeSeries']
61+
'SparseTimeSeries', 'Panel', 'Panel4D']
6262

6363
# these should be deperecated in the future
64-
deprecated_classes_in_future = ['Panel', 'Panel4D',
65-
'SparseList', 'Term']
64+
deprecated_classes_in_future = ['SparseList', 'Term']
6665

6766
# these should be removed from top-level namespace
6867
remove_classes_from_top_level_namespace = ['Expr']

pandas/core/common.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from pandas.compat import long, zip, iteritems
1515
from pandas.core.config import get_option
1616
from pandas.types.generic import ABCSeries
17-
from pandas.types.common import _NS_DTYPE, is_integer
17+
from pandas.types.common import _NS_DTYPE
1818
from pandas.types.inference import _iterable_not_string
1919
from pandas.types.missing import isnull
2020
from pandas.api import types
@@ -31,7 +31,7 @@ def wrapper(*args, **kwargs):
3131
warnings.warn("pandas.core.common.{t} is deprecated. "
3232
"import from the public API: "
3333
"pandas.api.types.{t} instead".format(t=t),
34-
FutureWarning, stacklevel=2)
34+
FutureWarning, stacklevel=3)
3535
return getattr(types, t)(*args, **kwargs)
3636
return wrapper
3737

@@ -57,7 +57,7 @@ def wrapper(*args, **kwargs):
5757
"These are not longer public API functions, "
5858
"but can be imported from "
5959
"pandas.types.common.{t} instead".format(t=t),
60-
FutureWarning, stacklevel=2)
60+
FutureWarning, stacklevel=3)
6161
return getattr(common, t)(*args, **kwargs)
6262
return wrapper
6363

@@ -578,7 +578,7 @@ def _random_state(state=None):
578578
np.random.RandomState
579579
"""
580580

581-
if is_integer(state):
581+
if types.is_integer(state):
582582
return np.random.RandomState(state)
583583
elif isinstance(state, np.random.RandomState):
584584
return state

pandas/core/panel4d.py

+15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
""" Panel4D: a 4-d dict like collection of panels """
22

3+
import warnings
34
from pandas.core.panelnd import create_nd_panel_factory
45
from pandas.core.panel import Panel
56

@@ -18,6 +19,11 @@
1819
having 4 named dimensions. It is intended as a test bed for more
1920
N-Dimensional named containers.
2021
22+
DEPRECATED. Panel4D is deprecated and will be removed in a future version.
23+
The recommended way to represent these types of n-dimensional data are with
24+
the `xarray package <http://xarray.pydata.org/en/stable/>`__.
25+
Pandas provides a `.to_xarray()` method to automate this conversion.
26+
2127
Parameters
2228
----------
2329
data : ndarray (labels x items x major x minor), or dict of Panels
@@ -37,6 +43,15 @@
3743
def panel4d_init(self, data=None, labels=None, items=None, major_axis=None,
3844
minor_axis=None, copy=False, dtype=None):
3945

46+
# deprecation GH13564
47+
warnings.warn("\nPanel4D is deprecated and will be removed in a "
48+
"future version.\nThe recommended way to represent "
49+
"these types of n-dimensional data are with\n"
50+
"the `xarray package "
51+
"<http://xarray.pydata.org/en/stable/>`__.\n"
52+
"Pandas provides a `.to_xarray()` method to help "
53+
"automate this conversion.\n",
54+
FutureWarning, stacklevel=2)
4055
self._init_data(data=data, labels=labels, items=items,
4156
major_axis=major_axis, minor_axis=minor_axis, copy=copy,
4257
dtype=dtype)

pandas/core/panelnd.py

+18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
""" Factory methods to create N-D panels """
22

3+
import warnings
34
from pandas.compat import zip
45
import pandas.compat as compat
56

@@ -8,6 +9,11 @@ def create_nd_panel_factory(klass_name, orders, slices, slicer, aliases=None,
89
stat_axis=2, info_axis=0, ns=None):
910
""" manufacture a n-d class:
1011
12+
DEPRECATED. Panelnd is deprecated and will be removed in a future version.
13+
The recommended way to represent these types of n-dimensional data are with
14+
the `xarray package <http://xarray.pydata.org/en/stable/>`__.
15+
Pandas provides a `.to_xarray()` method to automate this conversion.
16+
1117
Parameters
1218
----------
1319
klass_name : the klass name
@@ -44,6 +50,18 @@ def create_nd_panel_factory(klass_name, orders, slices, slicer, aliases=None,
4450

4551
# define the methods ####
4652
def __init__(self, *args, **kwargs):
53+
54+
# deprecation GH13564
55+
warnings.warn("\n{klass} is deprecated and will be removed in a "
56+
"future version.\nThe recommended way to represent "
57+
"these types of n-dimensional data are with the\n"
58+
"`xarray package "
59+
"<http://xarray.pydata.org/en/stable/>`__.\n"
60+
"Pandas provides a `.to_xarray()` method to help "
61+
"automate this conversion.\n".format(
62+
klass=self.__class__.__name__),
63+
FutureWarning, stacklevel=2)
64+
4765
if not (kwargs.get('data') or len(args)):
4866
raise Exception("must supply at least a data argument to [%s]" %
4967
klass_name)

pandas/io/tests/test_packers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import nose
22

3-
import warnings
43
import os
54
import datetime
65
import numpy as np
@@ -545,7 +544,8 @@ def test_sparse_frame(self):
545544

546545
def test_sparse_panel(self):
547546

548-
with warnings.catch_warnings(record=True):
547+
with tm.assert_produces_warning(FutureWarning,
548+
check_stacklevel=False):
549549

550550
items = ['x', 'y', 'z']
551551
p = Panel(dict((i, tm.makeDataFrame().ix[:2, :2]) for i in items))

0 commit comments

Comments
 (0)