Skip to content

DEPR: remove some SparsePanel deprecation warnings in testing #11347

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

Merged
merged 1 commit into from
Oct 18, 2015
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
4 changes: 2 additions & 2 deletions pandas/core/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,8 +680,8 @@ def _combine(self, other, func, axis=0):
elif np.isscalar(other):
return self._combine_const(other, func)
else:
raise NotImplementedError(str(type(other)) +
' is not supported in combine operation with ' +
raise NotImplementedError(str(type(other)) +
' is not supported in combine operation with ' +
str(type(self)))

def _combine_const(self, other, func):
Expand Down
132 changes: 67 additions & 65 deletions pandas/sparse/tests/test_sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@

from pandas.sparse.tests.test_array import assert_sp_array_equal

import warnings
warnings.filterwarnings(action='ignore', category=FutureWarning)


def _test_data1():
# nan-based
arr = np.arange(20, dtype=float)
Expand Down Expand Up @@ -503,15 +499,6 @@ def check(a, b):
result = self.bseries + self.bseries.to_dense()
assert_sp_series_equal(result, self.bseries + self.bseries)

# @dec.knownfailureif(True, 'Known NumPy failer as of 1.5.1')
def test_operators_corner2(self):
raise nose.SkipTest('known failer on numpy 1.5.1')

# NumPy circumvents __r*__ operations
val = np.float64(3.0)
result = val - self.zbseries
assert_sp_series_equal(result, 3 - self.zbseries)

def test_binary_operators(self):

# skipping for now #####
Expand Down Expand Up @@ -1778,20 +1765,23 @@ def setUp(self):
'ItemC': panel_data3(),
'ItemD': panel_data1(),
}
self.panel = SparsePanel(self.data_dict)
with tm.assert_produces_warning(FutureWarning):
self.panel = SparsePanel(self.data_dict)

@staticmethod
def _test_op(panel, op):
# arithmetic tests
result = op(panel, 1)
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
result = op(panel, 1)
assert_sp_frame_equal(result['ItemA'], op(panel['ItemA'], 1))

def test_constructor(self):
self.assertRaises(ValueError, SparsePanel, self.data_dict,
items=['Item0', 'ItemA', 'ItemB'])
with tm.assertRaisesRegexp(TypeError,
"input must be a dict, a 'list' was passed"):
SparsePanel(['a', 'b', 'c'])
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
self.assertRaises(ValueError, SparsePanel, self.data_dict,
items=['Item0', 'ItemA', 'ItemB'])
with tm.assertRaisesRegexp(TypeError,
"input must be a dict, a 'list' was passed"):
SparsePanel(['a', 'b', 'c'])

# deprecation GH11157
def test_deprecation(self):
Expand All @@ -1800,13 +1790,15 @@ def test_deprecation(self):

# GH 9272
def test_constructor_empty(self):
sp = SparsePanel()
with tm.assert_produces_warning(FutureWarning):
sp = SparsePanel()
self.assertEqual(len(sp.items), 0)
self.assertEqual(len(sp.major_axis), 0)
self.assertEqual(len(sp.minor_axis), 0)

def test_from_dict(self):
fd = SparsePanel.from_dict(self.data_dict)
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
fd = SparsePanel.from_dict(self.data_dict)
assert_sp_panel_equal(fd, self.panel)

def test_pickle(self):
Expand All @@ -1830,21 +1822,25 @@ def test_to_dense(self):
assert_panel_equal(dwp, dwp2)

def test_to_frame(self):
def _compare_with_dense(panel):
slp = panel.to_frame()
dlp = panel.to_dense().to_frame()

self.assert_numpy_array_equal(slp.values, dlp.values)
self.assertTrue(slp.index.equals(dlp.index))
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):

def _compare_with_dense(panel):
slp = panel.to_frame()
dlp = panel.to_dense().to_frame()

_compare_with_dense(self.panel)
_compare_with_dense(self.panel.reindex(items=['ItemA']))
self.assert_numpy_array_equal(slp.values, dlp.values)
self.assertTrue(slp.index.equals(dlp.index))

zero_panel = SparsePanel(self.data_dict, default_fill_value=0)
self.assertRaises(Exception, zero_panel.to_frame)
_compare_with_dense(self.panel)
_compare_with_dense(self.panel.reindex(items=['ItemA']))

self.assertRaises(Exception, self.panel.to_frame,
filter_observations=False)
with tm.assert_produces_warning(FutureWarning):
zero_panel = SparsePanel(self.data_dict, default_fill_value=0)
self.assertRaises(Exception, zero_panel.to_frame)

self.assertRaises(Exception, self.panel.to_frame,
filter_observations=False)

def test_long_to_wide_sparse(self):
pass
Expand Down Expand Up @@ -1885,47 +1881,53 @@ def test_delitem_pop(self):
self.assertRaises(KeyError, self.panel.__delitem__, 'ItemC')

def test_copy(self):
cop = self.panel.copy()
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
cop = self.panel.copy()
assert_sp_panel_equal(cop, self.panel)

def test_reindex(self):
def _compare_with_dense(swp, items, major, minor):
swp_re = swp.reindex(items=items, major=major,
minor=minor)
dwp_re = swp.to_dense().reindex(items=items, major=major,
minor=minor)
assert_panel_equal(swp_re.to_dense(), dwp_re)

_compare_with_dense(self.panel, self.panel.items[:2],
self.panel.major_axis[::2],
self.panel.minor_axis[::2])
_compare_with_dense(self.panel, None,
self.panel.major_axis[::2],
self.panel.minor_axis[::2])

self.assertRaises(ValueError, self.panel.reindex)

# TODO: do something about this later...
self.assertRaises(Exception, self.panel.reindex,
items=['item0', 'ItemA', 'ItemB'])

# test copying
cp = self.panel.reindex(self.panel.major_axis, copy=True)
cp['ItemA']['E'] = cp['ItemA']['A']
self.assertNotIn('E', self.panel['ItemA'])
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):

def _compare_with_dense(swp, items, major, minor):
swp_re = swp.reindex(items=items, major=major,
minor=minor)
dwp_re = swp.to_dense().reindex(items=items, major=major,
minor=minor)
assert_panel_equal(swp_re.to_dense(), dwp_re)

_compare_with_dense(self.panel, self.panel.items[:2],
self.panel.major_axis[::2],
self.panel.minor_axis[::2])
_compare_with_dense(self.panel, None,
self.panel.major_axis[::2],
self.panel.minor_axis[::2])

self.assertRaises(ValueError, self.panel.reindex)

# TODO: do something about this later...
self.assertRaises(Exception, self.panel.reindex,
items=['item0', 'ItemA', 'ItemB'])

# test copying
cp = self.panel.reindex(self.panel.major_axis, copy=True)
cp['ItemA']['E'] = cp['ItemA']['A']
self.assertNotIn('E', self.panel['ItemA'])

def test_operators(self):
def _check_ops(panel):

def _dense_comp(op):
dense = panel.to_dense()
sparse_result = op(panel)
dense_result = op(dense)
assert_panel_equal(sparse_result.to_dense(), dense_result)
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
dense = panel.to_dense()
sparse_result = op(panel)
dense_result = op(dense)
assert_panel_equal(sparse_result.to_dense(), dense_result)

def _mixed_comp(op):
result = op(panel, panel.to_dense())
expected = op(panel.to_dense(), panel.to_dense())
assert_panel_equal(result, expected)
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
result = op(panel, panel.to_dense())
expected = op(panel.to_dense(), panel.to_dense())
assert_panel_equal(result, expected)

op1 = lambda x: x + 2

Expand Down
3 changes: 3 additions & 0 deletions pandas/stats/tests/test_moments.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ def setUp(self):
self._create_data()
warnings.simplefilter("ignore", category=FutureWarning)

def tearDown(self):
warnings.simplefilter("default", category=FutureWarning)

def test_centered_axis_validation(self):
# ok
mom.rolling_mean(Series(np.ones(10)),3,center=True ,axis=0)
Expand Down
12 changes: 4 additions & 8 deletions pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,15 +381,11 @@ def test_getitem_boolean(self):
assert_frame_equal(subframe_obj, subframe)

# test that Series indexers reindex
import warnings
warnings.filterwarnings(action='ignore', category=UserWarning)

indexer_obj = indexer_obj.reindex(self.tsframe.index[::-1])

subframe_obj = self.tsframe[indexer_obj]
assert_frame_equal(subframe_obj, subframe)
with tm.assert_produces_warning(UserWarning):
indexer_obj = indexer_obj.reindex(self.tsframe.index[::-1])

warnings.filterwarnings(action='default', category=UserWarning)
subframe_obj = self.tsframe[indexer_obj]
assert_frame_equal(subframe_obj, subframe)

# test df[df > 0]
for df in [ self.tsframe, self.mixed_frame, self.mixed_float, self.mixed_int ]:
Expand Down
3 changes: 1 addition & 2 deletions pandas/tests/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ class Generic(object):
_multiprocess_can_split_ = True

def setUp(self):
import warnings
warnings.filterwarnings(action='ignore', category=FutureWarning)
pass

@property
def _ndim(self):
Expand Down
2 changes: 0 additions & 2 deletions pandas/tests/test_multilevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ class TestMultiLevel(tm.TestCase):
_multiprocess_can_split_ = True

def setUp(self):
import warnings
warnings.filterwarnings(action='ignore', category=FutureWarning)

index = MultiIndex(levels=[['foo', 'bar', 'baz', 'qux'],
['one', 'two', 'three']],
Expand Down
35 changes: 30 additions & 5 deletions pandas/tests/test_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from inspect import getargspec
import operator
import nose
from functools import wraps

import numpy as np
import pandas as pd
Expand All @@ -17,6 +18,7 @@
import pandas.core.common as com
from pandas import compat
from pandas.compat import range, lrange, StringIO, OrderedDict
from pandas import SparsePanel

from pandas.util.testing import (assert_panel_equal,
assert_frame_equal,
Expand All @@ -31,6 +33,22 @@
import pandas.core.panel as panelm
import pandas.util.testing as tm

def ignore_sparse_panel_future_warning(func):
"""
decorator to ignore FutureWarning if we have a SparsePanel

can be removed when SparsePanel is fully removed
"""
@wraps(func)
def wrapper(self, *args, **kwargs):

if isinstance(self.panel, SparsePanel):
with assert_produces_warning(FutureWarning, check_stacklevel=False):
return func(self, *args, **kwargs)
else:
return func(self, *args, **kwargs)

return wrapper

class PanelTests(object):
panel = None
Expand All @@ -56,6 +74,7 @@ class SafeForLongAndSparse(object):
def test_repr(self):
foo = repr(self.panel)

@ignore_sparse_panel_future_warning
def test_copy_names(self):
for attr in ('major_axis', 'minor_axis'):
getattr(self.panel, attr).name = None
Expand Down Expand Up @@ -233,6 +252,7 @@ def test_get_plane_axes(self):
index, columns = self.panel._get_plane_axes('minor_axis')
index, columns = self.panel._get_plane_axes(0)

@ignore_sparse_panel_future_warning
def test_truncate(self):
dates = self.panel.major_axis
start, end = dates[1], dates[5]
Expand Down Expand Up @@ -293,6 +313,7 @@ def test_iteritems(self):
self.assertEqual(len(list(compat.iteritems(self.panel))),
len(self.panel.items))

@ignore_sparse_panel_future_warning
def test_combineFrame(self):
def check_op(op, name):
# items
Expand Down Expand Up @@ -321,7 +342,7 @@ def check_op(op, name):

assert_frame_equal(result.minor_xs(idx),
op(self.panel.minor_xs(idx), xs))
from pandas import SparsePanel

ops = ['add', 'sub', 'mul', 'truediv', 'floordiv']
if not compat.PY3:
ops.append('div')
Expand All @@ -348,23 +369,26 @@ def check_op(op, name):
com.pprint_thing("Failing operation: %r" % name)
raise

@ignore_sparse_panel_future_warning
def test_combinePanel(self):
result = self.panel.add(self.panel)
self.assert_panel_equal(result, self.panel * 2)

@ignore_sparse_panel_future_warning
def test_neg(self):
self.assert_panel_equal(-self.panel, self.panel * -1)

# issue 7692
def test_raise_when_not_implemented(self):
p = Panel(np.arange(3*4*5).reshape(3,4,5), items=['ItemA','ItemB','ItemC'],
p = Panel(np.arange(3*4*5).reshape(3,4,5), items=['ItemA','ItemB','ItemC'],
major_axis=pd.date_range('20130101',periods=4),minor_axis=list('ABCDE'))
d = p.sum(axis=1).ix[0]
ops = ['add', 'sub', 'mul', 'truediv', 'floordiv', 'div', 'mod', 'pow']
for op in ops:
with self.assertRaises(NotImplementedError):
getattr(p,op)(d, axis=0)

@ignore_sparse_panel_future_warning
def test_select(self):
p = self.panel

Expand Down Expand Up @@ -396,7 +420,9 @@ def test_get_value(self):
expected = self.panel[item][mnr][mjr]
assert_almost_equal(result, expected)

@ignore_sparse_panel_future_warning
def test_abs(self):

result = self.panel.abs()
result2 = abs(self.panel)
expected = np.abs(self.panel)
Expand Down Expand Up @@ -872,9 +898,6 @@ def assert_panel_equal(cls, x, y):
assert_panel_equal(x, y)

def setUp(self):
import warnings
warnings.filterwarnings(action='ignore', category=FutureWarning)

self.panel = _panel.copy()
self.panel.major_axis.name = None
self.panel.minor_axis.name = None
Expand Down Expand Up @@ -1534,6 +1557,7 @@ def test_transpose_copy(self):
panel.values[0, 1, 1] = np.nan
self.assertTrue(notnull(result.values[1, 0, 1]))

@ignore_sparse_panel_future_warning
def test_to_frame(self):
# filtered
filtered = self.panel.to_frame()
Expand Down Expand Up @@ -2313,6 +2337,7 @@ def test_to_string(self):
buf = StringIO()
self.panel.to_string(buf)

@ignore_sparse_panel_future_warning
def test_truncate(self):
dates = self.panel.index.levels[0]
start, end = dates[1], dates[5]
Expand Down
Loading