Skip to content

TST: limit printing of xfail cases & catch Performance Warnings #19001

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 4 commits into from
Dec 30, 2017
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
34 changes: 22 additions & 12 deletions pandas/tests/indexes/datetimes/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,20 +368,25 @@ def test_dti_add_offset_array(self, tz, box):
# GH#18849
dti = pd.date_range('2017-01-01', periods=2, tz=tz)
other = box([pd.offsets.MonthEnd(), pd.offsets.Day(n=2)])
res = dti + other

with tm.assert_produces_warning(PerformanceWarning):
res = dti + other
expected = DatetimeIndex([dti[n] + other[n] for n in range(len(dti))],
name=dti.name, freq='infer')
tm.assert_index_equal(res, expected)

res2 = other + dti
with tm.assert_produces_warning(PerformanceWarning):
res2 = other + dti
tm.assert_index_equal(res2, expected)

@pytest.mark.parametrize('box', [np.array, pd.Index])
def test_dti_sub_offset_array(self, tz, box):
# GH#18824
dti = pd.date_range('2017-01-01', periods=2, tz=tz)
other = box([pd.offsets.MonthEnd(), pd.offsets.Day(n=2)])
res = dti - other

with tm.assert_produces_warning(PerformanceWarning):
res = dti - other
expected = DatetimeIndex([dti[n] - other[n] for n in range(len(dti))],
name=dti.name, freq='infer')
tm.assert_index_equal(res, expected)
Expand All @@ -392,20 +397,25 @@ def test_dti_sub_offset_array(self, tz, box):
def test_dti_with_offset_series(self, tz, names):
# GH#18849
dti = pd.date_range('2017-01-01', periods=2, tz=tz, name=names[0])
other = pd.Series([pd.offsets.MonthEnd(), pd.offsets.Day(n=2)],
name=names[1])
other = Series([pd.offsets.MonthEnd(), pd.offsets.Day(n=2)],
name=names[1])

expected_add = pd.Series([dti[n] + other[n] for n in range(len(dti))],
name=names[2])
res = dti + other
expected_add = Series([dti[n] + other[n] for n in range(len(dti))],
name=names[2])

with tm.assert_produces_warning(PerformanceWarning):
res = dti + other
tm.assert_series_equal(res, expected_add)
res2 = other + dti

with tm.assert_produces_warning(PerformanceWarning):
res2 = other + dti
tm.assert_series_equal(res2, expected_add)

expected_sub = pd.Series([dti[n] - other[n] for n in range(len(dti))],
name=names[2])
expected_sub = Series([dti[n] - other[n] for n in range(len(dti))],
name=names[2])

res3 = dti - other
with tm.assert_produces_warning(PerformanceWarning):
res3 = dti - other
tm.assert_series_equal(res3, expected_sub)


Expand Down
37 changes: 35 additions & 2 deletions pandas/tests/indexing/test_coercion.py
Original file line number Diff line number Diff line change
Expand Up @@ -819,8 +819,8 @@ def test_replace_series(self, how, to_key, from_key):
assert obj.dtype == from_key

if (from_key.startswith('datetime') and to_key.startswith('datetime')):
pytest.xfail("different tz, currently mask_missing "
"raises SystemError")
# tested below
return

if how == 'dict':
replacer = dict(zip(self.rep[from_key], self.rep[to_key]))
Expand Down Expand Up @@ -849,5 +849,38 @@ def test_replace_series(self, how, to_key, from_key):

tm.assert_series_equal(result, exp)

# TODO(jreback) commented out to only have a single xfail printed
@pytest.mark.xfail(reason="different tz, "
"currently mask_missing raises SystemError")
# @pytest.mark.parametrize('how', ['dict', 'series'])
# @pytest.mark.parametrize('to_key', [
# 'datetime64[ns]', 'datetime64[ns, UTC]',
# 'datetime64[ns, US/Eastern]'])
# @pytest.mark.parametrize('from_key', [
# 'datetime64[ns]', 'datetime64[ns, UTC]',
# 'datetime64[ns, US/Eastern]'])
# def test_replace_series_datetime_datetime(self, how, to_key, from_key):
def test_replace_series_datetime_datetime(self):
how = 'dict'
to_key = 'datetime64[ns]'
from_key = 'datetime64[ns]'

index = pd.Index([3, 4], name='xxx')
obj = pd.Series(self.rep[from_key], index=index, name='yyy')
assert obj.dtype == from_key

if how == 'dict':
replacer = dict(zip(self.rep[from_key], self.rep[to_key]))
elif how == 'series':
replacer = pd.Series(self.rep[to_key], index=self.rep[from_key])
else:
raise ValueError

result = obj.replace(replacer)
exp = pd.Series(self.rep[to_key], index=index, name='yyy')
assert exp.dtype == to_key

tm.assert_series_equal(result, exp)

def test_replace_series_period(self):
pass
8 changes: 3 additions & 5 deletions pandas/tests/series/test_rank.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,9 @@ def test_rank_signature(self):
pytest.param([np.iinfo(np.int64).min, -100, 0, 1, 9999, 100000,
1e10, np.iinfo(np.int64).max],
'int64',
marks=pytest.mark.xfail(reason='''iNaT is equivalent to
minimum value of dtype
int64 pending issue
#16674'''),
),
marks=pytest.mark.xfail(
reason="iNaT is equivalent to minimum value of dtype"
"int64 pending issue #16674")),
([NegInfinity(), '1', 'A', 'BA', 'Ba', 'C', Infinity()],
'object')
])
Expand Down
10 changes: 5 additions & 5 deletions pandas/tests/tseries/offsets/test_offsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def _get_offset(self, klass, value=1, normalize=False):
else:
try:
klass = klass(value, normalize=normalize)
except:
except Exception:
klass = klass(normalize=normalize)
return klass

Expand Down Expand Up @@ -143,10 +143,10 @@ def test_apply_out_of_range(self, tz):

except tslib.OutOfBoundsDatetime:
raise
except (ValueError, KeyError) as e:
pytest.skip(
"cannot create out_of_range offset: {0} {1}".format(
str(self).split('.')[-1], e))
except (ValueError, KeyError):
# we are creating an invalid offset
# so ignore
pass


class TestCommon(Base):
Expand Down