Skip to content

Commit f39a9ce

Browse files
jschendeljreback
authored andcommitted
TST: Remove compat.PY2 and compat.PY3 flags from tests (#25817)
1 parent 8b56ea3 commit f39a9ce

File tree

93 files changed

+334
-1120
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+334
-1120
lines changed

pandas/tests/arithmetic/test_numeric.py

+3-13
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import numpy as np
1010
import pytest
1111

12-
from pandas.compat import PY3, Iterable
12+
from pandas.compat import Iterable
1313

1414
import pandas as pd
1515
from pandas import Index, Series, Timedelta, TimedeltaIndex
@@ -438,17 +438,12 @@ def test_div_equiv_binop(self):
438438
tm.assert_series_equal(result, expected)
439439

440440
def test_div_int(self, numeric_idx):
441-
# truediv under PY3
442441
idx = numeric_idx
443442
result = idx / 1
444-
expected = idx
445-
if PY3:
446-
expected = expected.astype('float64')
443+
expected = idx.astype('float64')
447444
tm.assert_index_equal(result, expected)
448445

449446
result = idx / 2
450-
if PY3:
451-
expected = expected.astype('float64')
452447
expected = Index(idx.values / 2)
453448
tm.assert_index_equal(result, expected)
454449

@@ -1013,13 +1008,8 @@ def test_numeric_compat2(self):
10131008
expected = pd.RangeIndex(-2, 8, 2)
10141009
tm.assert_index_equal(result, expected, exact=True)
10151010

1016-
# truediv under PY3
10171011
result = idx / 2
1018-
1019-
if PY3:
1020-
expected = pd.RangeIndex(0, 5, 1).astype('float64')
1021-
else:
1022-
expected = pd.RangeIndex(0, 5, 1)
1012+
expected = pd.RangeIndex(0, 5, 1).astype('float64')
10231013
tm.assert_index_equal(result, expected, exact=True)
10241014

10251015
result = idx / 4

pandas/tests/arrays/categorical/test_operators.py

-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import numpy as np
55
import pytest
66

7-
from pandas.compat import PY2
8-
97
import pandas as pd
108
from pandas import Categorical, DataFrame, Series, date_range
119
from pandas.tests.arrays.categorical.common import TestCategorical
@@ -19,7 +17,6 @@ def test_categories_none_comparisons(self):
1917
'a', 'c', 'c', 'c'], ordered=True)
2018
tm.assert_categorical_equal(factor, self.factor)
2119

22-
@pytest.mark.skipif(PY2, reason="pytest.raises match regex fails")
2320
def test_comparisons(self):
2421

2522
result = self.factor[self.factor == 'a']
@@ -190,7 +187,6 @@ def test_comparison_with_unknown_scalars(self):
190187
tm.assert_numpy_array_equal(cat != 4,
191188
np.array([True, True, True]))
192189

193-
@pytest.mark.skipif(PY2, reason="pytest.raises match regex fails")
194190
@pytest.mark.parametrize('data,reverse,base', [
195191
(list("abc"), list("cba"), list("bbb")),
196192
([1, 2, 3], [3, 2, 1], [2, 2, 2])]

pandas/tests/arrays/categorical/test_repr.py

+4-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import numpy as np
44

5-
from pandas.compat import PY3, u
5+
from pandas.compat import u
66

77
from pandas import (
88
Categorical, CategoricalIndex, Series, date_range, period_range,
@@ -60,26 +60,21 @@ def test_print_none_width(self):
6060
assert exp == repr(a)
6161

6262
def test_unicode_print(self):
63-
if PY3:
64-
_rep = repr
65-
else:
66-
_rep = unicode # noqa
67-
6863
c = Categorical(['aaaaa', 'bb', 'cccc'] * 20)
6964
expected = u"""\
7065
[aaaaa, bb, cccc, aaaaa, bb, ..., bb, cccc, aaaaa, bb, cccc]
7166
Length: 60
7267
Categories (3, object): [aaaaa, bb, cccc]"""
7368

74-
assert _rep(c) == expected
69+
assert repr(c) == expected
7570

7671
c = Categorical([u'ああああ', u'いいいいい', u'ううううううう'] * 20)
7772
expected = u"""\
7873
[ああああ, いいいいい, ううううううう, ああああ, いいいいい, ..., いいいいい, ううううううう, ああああ, いいいいい, ううううううう]
7974
Length: 60
8075
Categories (3, object): [ああああ, いいいいい, ううううううう]""" # noqa
8176

82-
assert _rep(c) == expected
77+
assert repr(c) == expected
8378

8479
# unicode option should not affect to Categorical, as it doesn't care
8580
# the repr width
@@ -90,7 +85,7 @@ def test_unicode_print(self):
9085
Length: 60
9186
Categories (3, object): [ああああ, いいいいい, ううううううう]""" # noqa
9287

93-
assert _rep(c) == expected
88+
assert repr(c) == expected
9489

9590
def test_categorical_repr(self):
9691
c = Categorical([1, 2, 3])

pandas/tests/arrays/test_numpy.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import pandas.util._test_decorators as td
99

1010
import pandas as pd
11-
from pandas import compat
1211
from pandas.arrays import PandasArray
1312
from pandas.core.arrays.numpy_ import PandasDtype
1413
import pandas.util.testing as tm
@@ -42,8 +41,7 @@ def any_numpy_array(request):
4241
('float', True),
4342
('complex', True),
4443
('str', False),
45-
pytest.param('bytes', False,
46-
marks=pytest.mark.skipif(compat.PY2, reason="PY2")),
44+
('bytes', False),
4745
('datetime64[ns]', False),
4846
('object', False),
4947
('void', False),
@@ -60,8 +58,7 @@ def test_is_numeric(dtype, expected):
6058
('float', False),
6159
('complex', False),
6260
('str', False),
63-
pytest.param('bytes', False,
64-
marks=pytest.mark.skipif(compat.PY2, reason="PY2")),
61+
('bytes', False),
6562
('datetime64[ns]', False),
6663
('object', False),
6764
('void', False)

pandas/tests/computation/test_eval.py

+18-41
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from numpy.random import rand, randint, randn
88
import pytest
99

10-
from pandas.compat import PY3, reduce
10+
from pandas.compat import reduce
1111
from pandas.errors import PerformanceWarning
1212
import pandas.util._test_decorators as td
1313

@@ -102,7 +102,7 @@ def _bool_and_frame(lhs, rhs):
102102

103103

104104
def _is_py3_complex_incompat(result, expected):
105-
return (PY3 and isinstance(expected, (complex, np.complexfloating)) and
105+
return (isinstance(expected, (complex, np.complexfloating)) and
106106
np.isnan(result))
107107

108108

@@ -1133,50 +1133,27 @@ def test_truediv(self):
11331133
ex = 's / 1'
11341134
d = {'s': s} # noqa
11351135

1136-
if PY3:
1137-
res = self.eval(ex, truediv=False)
1138-
tm.assert_numpy_array_equal(res, np.array([1.0]))
1136+
res = self.eval(ex, truediv=False)
1137+
tm.assert_numpy_array_equal(res, np.array([1.0]))
11391138

1140-
res = self.eval(ex, truediv=True)
1141-
tm.assert_numpy_array_equal(res, np.array([1.0]))
1139+
res = self.eval(ex, truediv=True)
1140+
tm.assert_numpy_array_equal(res, np.array([1.0]))
11421141

1143-
res = self.eval('1 / 2', truediv=True)
1144-
expec = 0.5
1145-
assert res == expec
1142+
res = self.eval('1 / 2', truediv=True)
1143+
expec = 0.5
1144+
assert res == expec
11461145

1147-
res = self.eval('1 / 2', truediv=False)
1148-
expec = 0.5
1149-
assert res == expec
1146+
res = self.eval('1 / 2', truediv=False)
1147+
expec = 0.5
1148+
assert res == expec
11501149

1151-
res = self.eval('s / 2', truediv=False)
1152-
expec = 0.5
1153-
assert res == expec
1150+
res = self.eval('s / 2', truediv=False)
1151+
expec = 0.5
1152+
assert res == expec
11541153

1155-
res = self.eval('s / 2', truediv=True)
1156-
expec = 0.5
1157-
assert res == expec
1158-
else:
1159-
res = self.eval(ex, truediv=False)
1160-
tm.assert_numpy_array_equal(res, np.array([1]))
1161-
1162-
res = self.eval(ex, truediv=True)
1163-
tm.assert_numpy_array_equal(res, np.array([1.0]))
1164-
1165-
res = self.eval('1 / 2', truediv=True)
1166-
expec = 0.5
1167-
assert res == expec
1168-
1169-
res = self.eval('1 / 2', truediv=False)
1170-
expec = 0
1171-
assert res == expec
1172-
1173-
res = self.eval('s / 2', truediv=False)
1174-
expec = 0
1175-
assert res == expec
1176-
1177-
res = self.eval('s / 2', truediv=True)
1178-
expec = 0.5
1179-
assert res == expec
1154+
res = self.eval('s / 2', truediv=True)
1155+
expec = 0.5
1156+
assert res == expec
11801157

11811158
def test_failing_subscript_with_name_error(self):
11821159
df = DataFrame(np.random.randn(5, 3)) # noqa

pandas/tests/dtypes/test_inference.py

+4-16
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import pytz
1818

1919
from pandas._libs import iNaT, lib, missing as libmissing
20-
from pandas.compat import PY2, StringIO, lrange, u
20+
from pandas.compat import StringIO, lrange, u
2121
import pandas.util._test_decorators as td
2222

2323
from pandas.core.dtypes import inference
@@ -30,7 +30,7 @@
3030
import pandas as pd
3131
from pandas import (
3232
Categorical, DataFrame, DateOffset, DatetimeIndex, Index, Interval, Period,
33-
Series, Timedelta, TimedeltaIndex, Timestamp, compat, isna)
33+
Series, Timedelta, TimedeltaIndex, Timestamp, isna)
3434
from pandas.util import testing as tm
3535

3636

@@ -286,18 +286,6 @@ def __hash__(self):
286286
# is_hashable()
287287
assert not inference.is_hashable(np.array([]))
288288

289-
# old-style classes in Python 2 don't appear hashable to
290-
# collections.Hashable but also seem to support hash() by default
291-
if PY2:
292-
293-
class OldStyleClass():
294-
pass
295-
296-
c = OldStyleClass()
297-
assert not isinstance(c, compat.Hashable)
298-
assert inference.is_hashable(c)
299-
hash(c) # this will not raise
300-
301289

302290
@pytest.mark.parametrize(
303291
"ll", [re.compile('ad')])
@@ -330,7 +318,7 @@ def test_is_recompilable_fails(ll):
330318
class TestInference(object):
331319

332320
def test_infer_dtype_bytes(self):
333-
compare = 'string' if PY2 else 'bytes'
321+
compare = 'bytes'
334322

335323
# string array of bytes
336324
arr = np.array(list('abc'), dtype='S1')
@@ -658,7 +646,7 @@ def test_unicode(self):
658646

659647
arr = [u'a', np.nan, u'c']
660648
result = lib.infer_dtype(arr, skipna=True)
661-
expected = 'unicode' if PY2 else 'string'
649+
expected = 'string'
662650
assert result == expected
663651

664652
@pytest.mark.parametrize('dtype, missing, skipna, expected', [

pandas/tests/extension/decimal/test_decimal.py

+6-17
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import pytest
77

88
import pandas as pd
9-
from pandas import compat
109
from pandas.tests.extension import base
1110
import pandas.util.testing as tm
1211

@@ -114,15 +113,12 @@ def assert_frame_equal(self, left, right, *args, **kwargs):
114113

115114

116115
class TestDtype(BaseDecimal, base.BaseDtypeTests):
117-
@pytest.mark.skipif(compat.PY2, reason="Context not hashable.")
118116
def test_hashable(self, dtype):
119117
pass
120118

121119

122120
class TestInterface(BaseDecimal, base.BaseInterfaceTests):
123-
124-
pytestmark = pytest.mark.skipif(compat.PY2,
125-
reason="Unhashble dtype in Py2.")
121+
pass
126122

127123

128124
class TestConstructors(BaseDecimal, base.BaseConstructorsTests):
@@ -134,8 +130,7 @@ def test_from_dtype(self, data):
134130

135131

136132
class TestReshaping(BaseDecimal, base.BaseReshapingTests):
137-
pytestmark = pytest.mark.skipif(compat.PY2,
138-
reason="Unhashble dtype in Py2.")
133+
pass
139134

140135

141136
class TestGetitem(BaseDecimal, base.BaseGetitemTests):
@@ -193,22 +188,19 @@ def test_value_counts(self, all_data, dropna):
193188

194189

195190
class TestCasting(BaseDecimal, base.BaseCastingTests):
196-
pytestmark = pytest.mark.skipif(compat.PY2,
197-
reason="Unhashble dtype in Py2.")
191+
pass
198192

199193

200194
class TestGroupby(BaseDecimal, base.BaseGroupbyTests):
201-
pytestmark = pytest.mark.skipif(compat.PY2,
202-
reason="Unhashble dtype in Py2.")
195+
pass
203196

204197

205198
class TestSetitem(BaseDecimal, base.BaseSetitemTests):
206199
pass
207200

208201

209202
class TestPrinting(BaseDecimal, base.BasePrintingTests):
210-
pytestmark = pytest.mark.skipif(compat.PY2,
211-
reason="Unhashble dtype in Py2.")
203+
pass
212204

213205

214206
# TODO(extension)
@@ -398,9 +390,6 @@ def _formatting_values(self):
398390
return np.array(self)
399391

400392
ser = pd.Series(DecimalArray2([decimal.Decimal('1.0')]))
401-
# different levels for 2 vs. 3
402-
check_stacklevel = compat.PY3
403393

404-
with tm.assert_produces_warning(DeprecationWarning,
405-
check_stacklevel=check_stacklevel):
394+
with tm.assert_produces_warning(DeprecationWarning, check_stacklevel=True):
406395
repr(ser)

pandas/tests/extension/json/array.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
Note:
77
8-
We currently store lists of UserDicts (Py3 only). Pandas has a few places
8+
We currently store lists of UserDicts. Pandas has a few places
99
internally that specifically check for dicts, and does non-scalar things
1010
in that case. We *want* the dictionaries to be treated as scalars, so we
1111
hack around pandas by using UserDicts.

pandas/tests/extension/json/test_json.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@
33

44
import pytest
55

6-
from pandas.compat import PY2, PY36
6+
from pandas.compat import PY36
77

88
import pandas as pd
99
from pandas.tests.extension import base
1010
import pandas.util.testing as tm
1111

1212
from .array import JSONArray, JSONDtype, make_data
1313

14-
pytestmark = pytest.mark.skipif(PY2, reason="Py2 doesn't have a UserDict")
15-
1614

1715
@pytest.fixture
1816
def dtype():

0 commit comments

Comments
 (0)