Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEPR: remove tm.makePanel and all usages #25231

Merged
merged 2 commits into from
Feb 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions pandas/tests/frame/test_reshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from datetime import datetime
import itertools
from warnings import catch_warnings, simplefilter

import numpy as np
import pytest
Expand Down Expand Up @@ -49,14 +48,6 @@ def test_pivot(self):
assert pivoted.index.name == 'index'
assert pivoted.columns.names == (None, 'columns')

with catch_warnings(record=True):
# pivot multiple columns
simplefilter("ignore", FutureWarning)
wp = tm.makePanel()
lp = wp.to_frame()
df = lp.reset_index()
tm.assert_frame_equal(df.pivot('major', 'minor'), lp.unstack())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would this test not need to replaced with a similar test not dependent on tm.makePanel?


def test_pivot_duplicates(self):
data = DataFrame({'a': ['bar', 'bar', 'foo', 'foo', 'foo'],
'b': ['one', 'two', 'one', 'one', 'two'],
Expand Down
52 changes: 1 addition & 51 deletions pandas/tests/generic/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,23 +740,11 @@ def test_squeeze(self):
tm.assert_series_equal(s.squeeze(), s)
for df in [tm.makeTimeDataFrame()]:
tm.assert_frame_equal(df.squeeze(), df)
with catch_warnings(record=True):
simplefilter("ignore", FutureWarning)
for p in [tm.makePanel()]:
tm.assert_panel_equal(p.squeeze(), p)

# squeezing
df = tm.makeTimeDataFrame().reindex(columns=['A'])
tm.assert_series_equal(df.squeeze(), df['A'])

with catch_warnings(record=True):
simplefilter("ignore", FutureWarning)
p = tm.makePanel().reindex(items=['ItemA'])
tm.assert_frame_equal(p.squeeze(), p['ItemA'])

p = tm.makePanel().reindex(items=['ItemA'], minor_axis=['A'])
tm.assert_series_equal(p.squeeze(), p.loc['ItemA', :, 'A'])

# don't fail with 0 length dimensions GH11229 & GH8999
empty_series = Series([], name='five')
empty_frame = DataFrame([empty_series])
Expand Down Expand Up @@ -789,23 +777,13 @@ def test_numpy_squeeze(self):
tm.assert_series_equal(np.squeeze(df), df['A'])

def test_transpose(self):
msg = (r"transpose\(\) got multiple values for "
r"keyword argument 'axes'")
for s in [tm.makeFloatSeries(), tm.makeStringSeries(),
tm.makeObjectSeries()]:
# calls implementation in pandas/core/base.py
tm.assert_series_equal(s.transpose(), s)
for df in [tm.makeTimeDataFrame()]:
tm.assert_frame_equal(df.transpose().transpose(), df)

with catch_warnings(record=True):
simplefilter("ignore", FutureWarning)
for p in [tm.makePanel()]:
tm.assert_panel_equal(p.transpose(2, 0, 1)
.transpose(1, 2, 0), p)
with pytest.raises(TypeError, match=msg):
p.transpose(2, 0, 1, axes=(2, 0, 1))

def test_numpy_transpose(self):
msg = "the 'axes' parameter is not supported"

Expand All @@ -821,13 +799,6 @@ def test_numpy_transpose(self):
with pytest.raises(ValueError, match=msg):
np.transpose(df, axes=1)

with catch_warnings(record=True):
simplefilter("ignore", FutureWarning)
p = tm.makePanel()
tm.assert_panel_equal(np.transpose(
np.transpose(p, axes=(2, 0, 1)),
axes=(1, 2, 0)), p)

def test_take(self):
indices = [1, 5, -2, 6, 3, -1]
for s in [tm.makeFloatSeries(), tm.makeStringSeries(),
Expand All @@ -843,27 +814,12 @@ def test_take(self):
columns=df.columns)
tm.assert_frame_equal(out, expected)

indices = [-3, 2, 0, 1]
with catch_warnings(record=True):
simplefilter("ignore", FutureWarning)
for p in [tm.makePanel()]:
out = p.take(indices)
expected = Panel(data=p.values.take(indices, axis=0),
items=p.items.take(indices),
major_axis=p.major_axis,
minor_axis=p.minor_axis)
tm.assert_panel_equal(out, expected)

def test_take_invalid_kwargs(self):
indices = [-3, 2, 0, 1]
s = tm.makeFloatSeries()
df = tm.makeTimeDataFrame()

with catch_warnings(record=True):
simplefilter("ignore", FutureWarning)
p = tm.makePanel()

for obj in (s, df, p):
for obj in (s, df):
msg = r"take\(\) got an unexpected keyword argument 'foo'"
with pytest.raises(TypeError, match=msg):
obj.take(indices, foo=2)
Expand Down Expand Up @@ -966,12 +922,6 @@ def test_equals(self):
assert a.equals(e)
assert e.equals(f)

def test_describe_raises(self):
with catch_warnings(record=True):
simplefilter("ignore", FutureWarning)
with pytest.raises(NotImplementedError):
tm.makePanel().describe()

def test_pipe(self):
df = DataFrame({'A': [1, 2, 3]})
f = lambda x, y: x ** y
Expand Down
23 changes: 1 addition & 22 deletions pandas/tests/generic/test_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@

from warnings import catch_warnings, simplefilter

import pandas.util._test_decorators as td

from pandas import Panel
import pandas.util.testing as tm
from pandas.util.testing import assert_almost_equal, assert_panel_equal
from pandas.util.testing import assert_panel_equal

from .test_generic import Generic

Expand All @@ -16,24 +13,6 @@ class TestPanel(Generic):
_typ = Panel
_comparator = lambda self, x, y: assert_panel_equal(x, y, by_blocks=True)

@td.skip_if_no('xarray', min_version='0.7.0')
def test_to_xarray(self):
from xarray import DataArray

with catch_warnings(record=True):
simplefilter("ignore", FutureWarning)
p = tm.makePanel()

result = p.to_xarray()
assert isinstance(result, DataArray)
assert len(result.coords) == 3
assert_almost_equal(list(result.coords.keys()),
['items', 'major_axis', 'minor_axis'])
assert len(result.dims) == 3

# idempotency
assert_panel_equal(result.to_pandas(), p)


# run all the tests, but wrap each in a warning catcher
for t in ['test_rename', 'test_get_numeric_data',
Expand Down
22 changes: 0 additions & 22 deletions pandas/tests/indexing/test_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,28 +122,6 @@ def test_panel_getitem(self):
test1 = panel.loc[:, "2002"]
tm.assert_panel_equal(test1, test2)

# GH8710
# multi-element getting with a list
panel = tm.makePanel()

expected = panel.iloc[[0, 1]]

result = panel.loc[['ItemA', 'ItemB']]
tm.assert_panel_equal(result, expected)

result = panel.loc[['ItemA', 'ItemB'], :, :]
tm.assert_panel_equal(result, expected)

result = panel[['ItemA', 'ItemB']]
tm.assert_panel_equal(result, expected)

result = panel.loc['ItemA':'ItemB']
tm.assert_panel_equal(result, expected)

with catch_warnings(record=True):
result = panel.ix[['ItemA', 'ItemB']]
tm.assert_panel_equal(result, expected)

# with an object-like
# GH 9140
class TestObject(object):
Expand Down
6 changes: 0 additions & 6 deletions pandas/tests/io/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,12 +605,6 @@ def test_to_sql_series(self):
s2 = sql.read_sql_query("SELECT * FROM test_series", self.conn)
tm.assert_frame_equal(s.to_frame(), s2)

@pytest.mark.filterwarnings("ignore:\\nPanel:FutureWarning")
def test_to_sql_panel(self):
panel = tm.makePanel()
pytest.raises(NotImplementedError, sql.to_sql, panel,
'test_panel', self.conn)

def test_roundtrip(self):
sql.to_sql(self.test_frame1, 'test_frame_roundtrip',
con=self.conn)
Expand Down
19 changes: 12 additions & 7 deletions pandas/tests/reshape/test_reshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,23 +580,28 @@ def test_get_dummies_duplicate_columns(self, df):

class TestCategoricalReshape(object):

@pytest.mark.filterwarnings("ignore:\\nPanel:FutureWarning")
def test_reshaping_panel_categorical(self):
def test_reshaping_multi_index_categorical(self):

p = tm.makePanel()
p['str'] = 'foo'
df = p.to_frame()
# construct a MultiIndexed DataFrame formerly created
# via `tm.makePanel().to_frame()`
cols = ['ItemA', 'ItemB', 'ItemC']
data = {c: tm.makeTimeDataFrame() for c in cols}
df = pd.concat({c: data[c].stack() for c in data}, axis='columns')
df.index.names = ['major', 'minor']
df['str'] = 'foo'

dti = df.index.levels[0]

df['category'] = df['str'].astype('category')
result = df['category'].unstack()

c = Categorical(['foo'] * len(p.major_axis))
c = Categorical(['foo'] * len(dti))
expected = DataFrame({'A': c.copy(),
'B': c.copy(),
'C': c.copy(),
'D': c.copy()},
columns=Index(list('ABCD'), name='minor'),
index=p.major_axis.set_names('major'))
index=dti)
tm.assert_frame_equal(result, expected)


Expand Down
Loading