Skip to content

Commit 22f9d0d

Browse files
authored
Revert "MAINT: Remove Long and WidePanel (pandas-dev#15748)" (pandas-dev#15802)
This reverts commit bff47f2.
1 parent 156bfd2 commit 22f9d0d

File tree

9 files changed

+64
-17
lines changed

9 files changed

+64
-17
lines changed

asv_bench/benchmarks/pandas_vb_common.py

+5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
except:
2626
pass
2727

28+
try:
29+
Panel = Panel
30+
except Exception:
31+
Panel = WidePanel
32+
2833
# didn't add to namespace until later
2934
try:
3035
from pandas.core.index import MultiIndex

bench/bench_join_panel.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ def reindex_on_axis(panels, axis, axis_reindex):
4545
return p
4646

4747

48-
# Does the job but inefficient. It is better to handle
49-
# this like you read a table in pytables.
48+
# does the job but inefficient (better to handle like you read a table in
49+
# pytables...e.g create a LongPanel then convert to Wide)
5050
def create_panels_join(cls, panels):
5151
""" given an array of panels's, create a single panel """
5252
panels = [a for a in panels if a is not None]

doc/source/whatsnew/v0.20.0.txt

-1
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,6 @@ Removal of prior version deprecations/changes
814814
- The ``take_last`` parameter has been dropped from ``duplicated()``, ``drop_duplicates()``, ``nlargest()``, and ``nsmallest()`` methods (:issue:`10236`, :issue:`10792`, :issue:`10920`)
815815
- ``Series``, ``Index``, and ``DataFrame`` have dropped the ``sort`` and ``order`` methods (:issue:`10726`)
816816
- Where clauses in ``pytables`` are only accepted as strings and expressions types and not other data-types (:issue:`12027`)
817-
- The ``LongPanel`` and ``WidePanel`` classes have been removed (:issue:`10892`)
818817

819818
.. _whatsnew_0200.performance:
820819

pandas/core/api.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from pandas.core.series import Series
1717
from pandas.core.frame import DataFrame
18-
from pandas.core.panel import Panel
18+
from pandas.core.panel import Panel, WidePanel
1919
from pandas.core.panel4d import Panel4D
2020
from pandas.core.reshape import (pivot_simple as pivot, get_dummies,
2121
lreshape, wide_to_long)

pandas/core/panel.py

+23
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
# pylint: disable=E1103,W0231,W0212,W0621
55
from __future__ import division
66

7+
import warnings
8+
79
import numpy as np
810

911
from pandas.types.cast import (infer_dtype_from_scalar,
@@ -1554,3 +1556,24 @@ def f(self, other, axis=0):
15541556
ops.add_special_arithmetic_methods(Panel, **ops.panel_special_funcs)
15551557
Panel._add_aggregate_operations()
15561558
Panel._add_numeric_operations()
1559+
1560+
1561+
# legacy
1562+
class WidePanel(Panel):
1563+
1564+
def __init__(self, *args, **kwargs):
1565+
# deprecation, #10892
1566+
warnings.warn("WidePanel is deprecated. Please use Panel",
1567+
FutureWarning, stacklevel=2)
1568+
1569+
super(WidePanel, self).__init__(*args, **kwargs)
1570+
1571+
1572+
class LongPanel(DataFrame):
1573+
1574+
def __init__(self, *args, **kwargs):
1575+
# deprecation, #10892
1576+
warnings.warn("LongPanel is deprecated. Please use DataFrame",
1577+
FutureWarning, stacklevel=2)
1578+
1579+
super(LongPanel, self).__init__(*args, **kwargs)

pandas/tests/api/test_api.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ class TestPDApi(Base, tm.TestCase):
5454
'TimedeltaIndex', 'Timestamp']
5555

5656
# these are already deprecated; awaiting removal
57-
deprecated_classes = ['Panel4D', 'SparseList', 'Expr', 'Term']
57+
deprecated_classes = ['WidePanel', 'Panel4D',
58+
'SparseList', 'Expr', 'Term']
5859

5960
# these should be deprecated in the future
6061
deprecated_classes_in_future = ['Panel']

pandas/tests/io/test_pytables.py

+3
Original file line numberDiff line numberDiff line change
@@ -2964,6 +2964,9 @@ def _check(left, right):
29642964
# empty
29652965
# self._check_roundtrip(wp.to_frame()[:0], _check)
29662966

2967+
def test_longpanel(self):
2968+
pass
2969+
29672970
def test_overwrite_node(self):
29682971

29692972
with ensure_clean_store(self.path) as store:

pandas/tests/test_panel.py

+23-12
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ def wrapper(x):
178178

179179
class SafeForSparse(object):
180180

181+
@classmethod
182+
def assert_panel_equal(cls, x, y):
183+
assert_panel_equal(x, y)
184+
181185
def test_get_axis(self):
182186
assert (self.panel._get_axis(0) is self.panel.items)
183187
assert (self.panel._get_axis(1) is self.panel.major_axis)
@@ -342,10 +346,10 @@ def check_op(op, name):
342346

343347
def test_combinePanel(self):
344348
result = self.panel.add(self.panel)
345-
assert_panel_equal(result, self.panel * 2)
349+
self.assert_panel_equal(result, self.panel * 2)
346350

347351
def test_neg(self):
348-
assert_panel_equal(-self.panel, self.panel * -1)
352+
self.assert_panel_equal(-self.panel, self.panel * -1)
349353

350354
# issue 7692
351355
def test_raise_when_not_implemented(self):
@@ -365,22 +369,22 @@ def test_select(self):
365369
# select items
366370
result = p.select(lambda x: x in ('ItemA', 'ItemC'), axis='items')
367371
expected = p.reindex(items=['ItemA', 'ItemC'])
368-
assert_panel_equal(result, expected)
372+
self.assert_panel_equal(result, expected)
369373

370374
# select major_axis
371375
result = p.select(lambda x: x >= datetime(2000, 1, 15), axis='major')
372376
new_major = p.major_axis[p.major_axis >= datetime(2000, 1, 15)]
373377
expected = p.reindex(major=new_major)
374-
assert_panel_equal(result, expected)
378+
self.assert_panel_equal(result, expected)
375379

376380
# select minor_axis
377381
result = p.select(lambda x: x in ('D', 'A'), axis=2)
378382
expected = p.reindex(minor=['A', 'D'])
379-
assert_panel_equal(result, expected)
383+
self.assert_panel_equal(result, expected)
380384

381385
# corner case, empty thing
382386
result = p.select(lambda x: x in ('foo', ), axis='items')
383-
assert_panel_equal(result, p.reindex(items=[]))
387+
self.assert_panel_equal(result, p.reindex(items=[]))
384388

385389
def test_get_value(self):
386390
for item in self.panel.items:
@@ -395,8 +399,8 @@ def test_abs(self):
395399
result = self.panel.abs()
396400
result2 = abs(self.panel)
397401
expected = np.abs(self.panel)
398-
assert_panel_equal(result, expected)
399-
assert_panel_equal(result2, expected)
402+
self.assert_panel_equal(result, expected)
403+
self.assert_panel_equal(result2, expected)
400404

401405
df = self.panel['ItemA']
402406
result = df.abs()
@@ -863,6 +867,10 @@ def test_set_value(self):
863867
class TestPanel(tm.TestCase, PanelTests, CheckIndexing, SafeForLongAndSparse,
864868
SafeForSparse):
865869

870+
@classmethod
871+
def assert_panel_equal(cls, x, y):
872+
assert_panel_equal(x, y)
873+
866874
def setUp(self):
867875
self.panel = _panel.copy()
868876
self.panel.major_axis.name = None
@@ -1959,7 +1967,7 @@ def test_round(self):
19591967
major_axis=pd.date_range('1/1/2000', periods=5),
19601968
minor_axis=['A', 'B'])
19611969
result = p.round()
1962-
assert_panel_equal(expected, result)
1970+
self.assert_panel_equal(expected, result)
19631971

19641972
def test_numpy_round(self):
19651973
values = [[[-3.2, 2.2], [0, -4.8213], [3.123, 123.12],
@@ -1975,7 +1983,7 @@ def test_numpy_round(self):
19751983
major_axis=pd.date_range('1/1/2000', periods=5),
19761984
minor_axis=['A', 'B'])
19771985
result = np.round(p)
1978-
assert_panel_equal(expected, result)
1986+
self.assert_panel_equal(expected, result)
19791987

19801988
msg = "the 'out' parameter is not supported"
19811989
tm.assertRaisesRegexp(ValueError, msg, np.round, p, out=p)
@@ -2262,12 +2270,15 @@ def test_all_any_unhandled(self):
22622270
self.assertRaises(NotImplementedError, self.panel.any, bool_only=True)
22632271

22642272

2265-
class TestPanelFrame(tm.TestCase):
2273+
class TestLongPanel(tm.TestCase):
22662274
"""
2267-
Check that conversions to and from Panel to DataFrame work.
2275+
LongPanel no longer exists, but...
22682276
"""
22692277

22702278
def setUp(self):
2279+
import warnings
2280+
warnings.filterwarnings(action='ignore', category=FutureWarning)
2281+
22712282
panel = tm.makePanel()
22722283
tm.add_nans(panel)
22732284

vb_suite/pandas_vb_common.py

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
except:
1919
import pandas._libs.lib as lib
2020

21+
try:
22+
Panel = WidePanel
23+
except Exception:
24+
pass
25+
2126
# didn't add to namespace until later
2227
try:
2328
from pandas.core.index import MultiIndex

0 commit comments

Comments
 (0)