From 14cb2de443072d19f7a4b3169c6ec039e24df644 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Tue, 20 Nov 2018 12:32:08 -0800 Subject: [PATCH] move misplaced modulo test --- pandas/tests/arithmetic/test_numeric.py | 38 +++++++++++++++++++++++++ pandas/tests/series/test_analytics.py | 36 ----------------------- 2 files changed, 38 insertions(+), 36 deletions(-) diff --git a/pandas/tests/arithmetic/test_numeric.py b/pandas/tests/arithmetic/test_numeric.py index f1023148aaf1c..c3cd9f0f43559 100644 --- a/pandas/tests/arithmetic/test_numeric.py +++ b/pandas/tests/arithmetic/test_numeric.py @@ -597,6 +597,44 @@ def test_operators_frame(self): tm.assert_series_equal(ts / ts, ts / df['A'], check_names=False) + # TODO: this came from tests.series.test_analytics, needs cleannup and + # de-duplication with test_modulo above + def test_modulo2(self): + with np.errstate(all='ignore'): + + # GH#3590, modulo as ints + p = pd.DataFrame({'first': [3, 4, 5, 8], 'second': [0, 0, 0, 3]}) + result = p['first'] % p['second'] + expected = Series(p['first'].values % p['second'].values, + dtype='float64') + expected.iloc[0:3] = np.nan + tm.assert_series_equal(result, expected) + + result = p['first'] % 0 + expected = Series(np.nan, index=p.index, name='first') + tm.assert_series_equal(result, expected) + + p = p.astype('float64') + result = p['first'] % p['second'] + expected = Series(p['first'].values % p['second'].values) + tm.assert_series_equal(result, expected) + + p = p.astype('float64') + result = p['first'] % p['second'] + result2 = p['second'] % p['first'] + assert not result.equals(result2) + + # GH#9144 + s = Series([0, 1]) + + result = s % 0 + expected = Series([np.nan, np.nan]) + tm.assert_series_equal(result, expected) + + result = 0 % s + expected = Series([np.nan, 0.0]) + tm.assert_series_equal(result, expected) + class TestAdditionSubtraction(object): # __add__, __sub__, __radd__, __rsub__, __iadd__, __isub__ diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index a5a7cc2217864..86b471492263c 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -681,42 +681,6 @@ def test_all_any_params(self): pytest.raises(NotImplementedError, s.any, bool_only=True) pytest.raises(NotImplementedError, s.all, bool_only=True) - def test_modulo(self): - with np.errstate(all='ignore'): - - # GH3590, modulo as ints - p = DataFrame({'first': [3, 4, 5, 8], 'second': [0, 0, 0, 3]}) - result = p['first'] % p['second'] - expected = Series(p['first'].values % p['second'].values, - dtype='float64') - expected.iloc[0:3] = np.nan - assert_series_equal(result, expected) - - result = p['first'] % 0 - expected = Series(np.nan, index=p.index, name='first') - assert_series_equal(result, expected) - - p = p.astype('float64') - result = p['first'] % p['second'] - expected = Series(p['first'].values % p['second'].values) - assert_series_equal(result, expected) - - p = p.astype('float64') - result = p['first'] % p['second'] - result2 = p['second'] % p['first'] - assert not result.equals(result2) - - # GH 9144 - s = Series([0, 1]) - - result = s % 0 - expected = Series([nan, nan]) - assert_series_equal(result, expected) - - result = 0 % s - expected = Series([nan, 0.0]) - assert_series_equal(result, expected) - @td.skip_if_no_scipy def test_corr(self, datetime_series): import scipy.stats as stats