From 649f6ce405b77f9d1cccf97aa870a57ec9e5965f Mon Sep 17 00:00:00 2001 From: gfyoung Date: Sun, 24 Mar 2019 17:11:09 -0700 Subject: [PATCH] CLN: Remove vestigial references to PY2 in tests --- pandas/tests/arithmetic/test_period.py | 42 +++++++++++--------------- pandas/tests/frame/test_indexing.py | 6 ++-- pandas/tests/series/test_repr.py | 6 ++-- 3 files changed, 21 insertions(+), 33 deletions(-) diff --git a/pandas/tests/arithmetic/test_period.py b/pandas/tests/arithmetic/test_period.py index 982aef5497b8b..b8ae0895bda06 100644 --- a/pandas/tests/arithmetic/test_period.py +++ b/pandas/tests/arithmetic/test_period.py @@ -1046,34 +1046,26 @@ def test_pi_ops(self): exp = pd.Index([0 * off, -1 * off, -2 * off, -3 * off], name='idx') tm.assert_index_equal(result, exp) - @pytest.mark.parametrize('ng', ["str", 1.5]) - def test_parr_ops_errors(self, ng, box_with_array): - idx = PeriodIndex(['2011-01', '2011-02', '2011-03', '2011-04'], - freq='M', name='idx') + @pytest.mark.parametrize("ng", ["str", 1.5]) + @pytest.mark.parametrize("func", [ + lambda obj, ng: obj + ng, + lambda obj, ng: ng + obj, + lambda obj, ng: obj - ng, + lambda obj, ng: ng - obj, + lambda obj, ng: np.add(obj, ng), + lambda obj, ng: np.add(ng, obj), + lambda obj, ng: np.subtract(obj, ng), + lambda obj, ng: np.subtract(ng, obj), + ]) + def test_parr_ops_errors(self, ng, func, box_with_array): + idx = PeriodIndex(["2011-01", "2011-02", "2011-03", "2011-04"], + freq="M", name="idx") obj = tm.box_expected(idx, box_with_array) - - msg = r"unsupported operand type\(s\)" - with pytest.raises(TypeError, match=msg): - obj + ng - - with pytest.raises(TypeError): - # error message differs between PY2 and 3 - ng + obj + msg = (r"unsupported operand type\(s\)|can only concatenate|" + r"must be str|object to str implicitly") with pytest.raises(TypeError, match=msg): - obj - ng - - with pytest.raises(TypeError): - np.add(obj, ng) - - with pytest.raises(TypeError): - np.add(ng, obj) - - with pytest.raises(TypeError): - np.subtract(obj, ng) - - with pytest.raises(TypeError): - np.subtract(ng, obj) + func(obj, ng) def test_pi_ops_nat(self): idx = PeriodIndex(['2011-01', '2011-02', 'NaT', '2011-04'], diff --git a/pandas/tests/frame/test_indexing.py b/pandas/tests/frame/test_indexing.py index 4d8b3abee6f0d..a24e623b8d56f 100644 --- a/pandas/tests/frame/test_indexing.py +++ b/pandas/tests/frame/test_indexing.py @@ -2581,11 +2581,9 @@ def test_boolean_indexing_mixed(self): assert_frame_equal(df2, expected) df['foo'] = 'test' - msg = ("boolean setting on mixed-type|" - "not supported between|" - "unorderable types") + msg = "not supported between instances|unorderable types" + with pytest.raises(TypeError, match=msg): - # TODO: This message should be the same in PY2/PY3 df[df > 0.3] = 1 def test_where(self): diff --git a/pandas/tests/series/test_repr.py b/pandas/tests/series/test_repr.py index 6c090e43e0946..63c787179a0b3 100644 --- a/pandas/tests/series/test_repr.py +++ b/pandas/tests/series/test_repr.py @@ -203,9 +203,7 @@ def test_index_repr_in_frame_with_nan(self): class TestCategoricalRepr(object): def test_categorical_repr_unicode(self): - # GH#21002 if len(index) > 60, sys.getdefaultencoding()=='ascii', - # and we are working in PY2, then rendering a Categorical could raise - # UnicodeDecodeError by trying to decode when it shouldn't + # see gh-21002 class County(StringMixin): name = u'San Sebastián' @@ -214,7 +212,7 @@ class County(StringMixin): def __unicode__(self): return self.name + u', ' + self.state - cat = pd.Categorical([County() for n in range(61)]) + cat = pd.Categorical([County() for _ in range(61)]) idx = pd.Index(cat) ser = idx.to_series()