Skip to content

Commit 34d3e69

Browse files
committed
DEPS: remove PY37 check from tests (pandas-dev#34472)
1 parent f493979 commit 34d3e69

File tree

11 files changed

+66
-239
lines changed

11 files changed

+66
-239
lines changed

pandas/__init__.py

Lines changed: 51 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -184,181 +184,76 @@
184184
__git_version__ = v.get("full-revisionid")
185185
del get_versions, v
186186

187+
187188
# GH 27101
188189
# TODO: remove Panel compat in 1.0
189-
if pandas.compat.PY37:
190-
191-
def __getattr__(name):
192-
import warnings
193-
194-
if name == "Panel":
195-
196-
warnings.warn(
197-
"The Panel class is removed from pandas. Accessing it "
198-
"from the top-level namespace will also be removed in the next version",
199-
FutureWarning,
200-
stacklevel=2,
201-
)
202-
203-
class Panel:
204-
pass
205-
206-
return Panel
207-
208-
elif name == "datetime":
209-
warnings.warn(
210-
"The pandas.datetime class is deprecated "
211-
"and will be removed from pandas in a future version. "
212-
"Import from datetime module instead.",
213-
FutureWarning,
214-
stacklevel=2,
215-
)
216-
217-
from datetime import datetime as dt
218-
219-
return dt
220-
221-
elif name == "np":
222-
223-
warnings.warn(
224-
"The pandas.np module is deprecated "
225-
"and will be removed from pandas in a future version. "
226-
"Import numpy directly instead",
227-
FutureWarning,
228-
stacklevel=2,
229-
)
230-
import numpy as np
231-
232-
return np
233-
234-
elif name in {"SparseSeries", "SparseDataFrame"}:
235-
warnings.warn(
236-
f"The {name} class is removed from pandas. Accessing it from "
237-
"the top-level namespace will also be removed in the next version",
238-
FutureWarning,
239-
stacklevel=2,
240-
)
241-
242-
return type(name, (), {})
243-
244-
elif name == "SparseArray":
245-
246-
warnings.warn(
247-
"The pandas.SparseArray class is deprecated "
248-
"and will be removed from pandas in a future version. "
249-
"Use pandas.arrays.SparseArray instead.",
250-
FutureWarning,
251-
stacklevel=2,
252-
)
253-
from pandas.core.arrays.sparse import SparseArray as _SparseArray
190+
def __getattr__(name):
191+
import warnings
254192

255-
return _SparseArray
193+
if name == "Panel":
256194

257-
raise AttributeError(f"module 'pandas' has no attribute '{name}'")
195+
warnings.warn(
196+
"The Panel class is removed from pandas. Accessing it "
197+
"from the top-level namespace will also be removed in the next version",
198+
FutureWarning,
199+
stacklevel=2,
200+
)
258201

202+
class Panel:
203+
pass
259204

260-
else:
205+
return Panel
261206

262-
class Panel:
263-
pass
264-
265-
class SparseDataFrame:
266-
pass
267-
268-
class SparseSeries:
269-
pass
270-
271-
class __numpy:
272-
def __init__(self):
273-
import numpy as np
274-
import warnings
275-
276-
self.np = np
277-
self.warnings = warnings
278-
279-
def __getattr__(self, item):
280-
self.warnings.warn(
281-
"The pandas.np module is deprecated "
282-
"and will be removed from pandas in a future version. "
283-
"Import numpy directly instead",
284-
FutureWarning,
285-
stacklevel=2,
286-
)
287-
288-
try:
289-
return getattr(self.np, item)
290-
except AttributeError as err:
291-
raise AttributeError(f"module numpy has no attribute {item}") from err
292-
293-
np = __numpy()
294-
295-
class __Datetime(type):
207+
elif name == "datetime":
208+
warnings.warn(
209+
"The pandas.datetime class is deprecated "
210+
"and will be removed from pandas in a future version. "
211+
"Import from datetime module instead.",
212+
FutureWarning,
213+
stacklevel=2,
214+
)
296215

297216
from datetime import datetime as dt
298217

299-
datetime = dt
300-
301-
def __getattr__(cls, item):
302-
cls.emit_warning()
303-
304-
try:
305-
return getattr(cls.datetime, item)
306-
except AttributeError as err:
307-
raise AttributeError(
308-
f"module datetime has no attribute {item}"
309-
) from err
310-
311-
def __instancecheck__(cls, other):
312-
return isinstance(other, cls.datetime)
313-
314-
class __DatetimeSub(metaclass=__Datetime):
315-
def emit_warning(dummy=0):
316-
import warnings
317-
318-
warnings.warn(
319-
"The pandas.datetime class is deprecated "
320-
"and will be removed from pandas in a future version. "
321-
"Import from datetime instead.",
322-
FutureWarning,
323-
stacklevel=3,
324-
)
325-
326-
def __new__(cls, *args, **kwargs):
327-
cls.emit_warning()
328-
from datetime import datetime as dt
329-
330-
return dt(*args, **kwargs)
331-
332-
datetime = __DatetimeSub
218+
return dt
333219

334-
class __SparseArray(type):
220+
elif name == "np":
335221

336-
from pandas.core.arrays.sparse import SparseArray as sa
222+
warnings.warn(
223+
"The pandas.np module is deprecated "
224+
"and will be removed from pandas in a future version. "
225+
"Import numpy directly instead",
226+
FutureWarning,
227+
stacklevel=2,
228+
)
229+
import numpy as np
337230

338-
SparseArray = sa
231+
return np
339232

340-
def __instancecheck__(cls, other):
341-
return isinstance(other, cls.SparseArray)
233+
elif name in {"SparseSeries", "SparseDataFrame"}:
234+
warnings.warn(
235+
f"The {name} class is removed from pandas. Accessing it from "
236+
"the top-level namespace will also be removed in the next version",
237+
FutureWarning,
238+
stacklevel=2,
239+
)
342240

343-
class __SparseArraySub(metaclass=__SparseArray):
344-
def emit_warning(dummy=0):
345-
import warnings
241+
return type(name, (), {})
346242

347-
warnings.warn(
348-
"The pandas.SparseArray class is deprecated "
349-
"and will be removed from pandas in a future version. "
350-
"Use pandas.arrays.SparseArray instead.",
351-
FutureWarning,
352-
stacklevel=3,
353-
)
243+
elif name == "SparseArray":
354244

355-
def __new__(cls, *args, **kwargs):
356-
cls.emit_warning()
357-
from pandas.core.arrays.sparse import SparseArray as sa
245+
warnings.warn(
246+
"The pandas.SparseArray class is deprecated "
247+
"and will be removed from pandas in a future version. "
248+
"Use pandas.arrays.SparseArray instead.",
249+
FutureWarning,
250+
stacklevel=2,
251+
)
252+
from pandas.core.arrays.sparse import SparseArray as _SparseArray
358253

359-
return sa(*args, **kwargs)
254+
return _SparseArray
360255

361-
SparseArray = __SparseArraySub
256+
raise AttributeError(f"module 'pandas' has no attribute '{name}'")
362257

363258

364259
# module level doc-string

pandas/compat/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
from pandas._typing import F
1616

17-
PY37 = sys.version_info >= (3, 7)
1817
PY38 = sys.version_info >= (3, 8)
1918
PY39 = sys.version_info >= (3, 9)
2019
PYPY = platform.python_implementation() == "PyPy"

pandas/core/frame.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
Renamer,
5757
ValueKeyFunc,
5858
)
59-
from pandas.compat import PY37
6059
from pandas.compat._optional import import_optional_dependency
6160
from pandas.compat.numpy import function as nv
6261
from pandas.util._decorators import (
@@ -1066,9 +1065,7 @@ def itertuples(self, index=True, name="Pandas"):
10661065
# use integer indexing because of possible duplicate column names
10671066
arrays.extend(self.iloc[:, k] for k in range(len(self.columns)))
10681067

1069-
# Python versions before 3.7 support at most 255 arguments to constructors
1070-
can_return_named_tuples = PY37 or len(self.columns) + index < 255
1071-
if name is not None and can_return_named_tuples:
1068+
if name is not None:
10721069
itertuple = collections.namedtuple(name, fields, rename=True)
10731070
return map(itertuple._make, zip(*arrays))
10741071

pandas/tests/api/test_api.py

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,6 @@ class TestPDApi(Base):
100100
# these should be deprecated in the future
101101
deprecated_classes_in_future: List[str] = ["SparseArray"]
102102

103-
if not compat.PY37:
104-
classes.extend(["Panel", "SparseSeries", "SparseDataFrame"])
105-
# deprecated_modules.extend(["np", "datetime"])
106-
# deprecated_classes_in_future.extend(["SparseArray"])
107-
108103
# external modules exposed in pandas namespace
109104
modules: List[str] = []
110105

@@ -216,14 +211,6 @@ def test_api(self):
216211
+ self.funcs_to
217212
+ self.private_modules
218213
)
219-
if not compat.PY37:
220-
checkthese.extend(
221-
self.deprecated_modules
222-
+ self.deprecated_classes
223-
+ self.deprecated_classes_in_future
224-
+ self.deprecated_funcs_in_future
225-
+ self.deprecated_funcs
226-
)
227214
self.check(pd, checkthese, self.ignored)
228215

229216
def test_depr(self):
@@ -236,14 +223,7 @@ def test_depr(self):
236223
)
237224
for depr in deprecated_list:
238225
with tm.assert_produces_warning(FutureWarning):
239-
deprecated = getattr(pd, depr)
240-
if not compat.PY37:
241-
if depr == "datetime":
242-
deprecated.__getattr__(dir(pd.datetime.datetime)[-1])
243-
elif depr == "SparseArray":
244-
deprecated([])
245-
else:
246-
deprecated.__getattr__(dir(deprecated)[-1])
226+
_ = getattr(pd, depr)
247227

248228

249229
def test_datetime():

pandas/tests/extension/arrow/test_bool.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import numpy as np
22
import pytest
33

4-
from pandas.compat import PY37
5-
64
import pandas as pd
75
import pandas._testing as tm
86
from pandas.tests.extension import base
@@ -62,13 +60,11 @@ def test_from_dtype(self, data):
6260
def test_from_sequence_from_cls(self, data):
6361
super().test_from_sequence_from_cls(data)
6462

65-
@pytest.mark.skipif(not PY37, reason="timeout on Linux py36_locale")
6663
@pytest.mark.xfail(reason="pa.NULL is not recognised as scalar, GH-33899")
6764
def test_series_constructor_no_data_with_index(self, dtype, na_value):
6865
# pyarrow.lib.ArrowInvalid: only handle 1-dimensional arrays
6966
super().test_series_constructor_no_data_with_index(dtype, na_value)
7067

71-
@pytest.mark.skipif(not PY37, reason="timeout on Linux py36_locale")
7268
@pytest.mark.xfail(reason="pa.NULL is not recognised as scalar, GH-33899")
7369
def test_series_constructor_scalar_na_with_index(self, dtype, na_value):
7470
# pyarrow.lib.ArrowInvalid: only handle 1-dimensional arrays

pandas/tests/frame/test_api.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import numpy as np
77
import pytest
88

9-
from pandas.compat import PY37
109
from pandas.util._test_decorators import async_mark, skip_if_no
1110

1211
import pandas as pd
@@ -274,10 +273,7 @@ def test_itertuples(self, float_frame):
274273
# will raise SyntaxError if trying to create namedtuple
275274
tup3 = next(df3.itertuples())
276275
assert isinstance(tup3, tuple)
277-
if PY37:
278-
assert hasattr(tup3, "_fields")
279-
else:
280-
assert not hasattr(tup3, "_fields")
276+
assert hasattr(tup3, "_fields")
281277

282278
# GH 28282
283279
df_254_columns = DataFrame([{f"foo_{i}": f"bar_{i}" for i in range(254)}])
@@ -288,12 +284,7 @@ def test_itertuples(self, float_frame):
288284
df_255_columns = DataFrame([{f"foo_{i}": f"bar_{i}" for i in range(255)}])
289285
result_255_columns = next(df_255_columns.itertuples(index=False))
290286
assert isinstance(result_255_columns, tuple)
291-
292-
# Dataframes with >=255 columns will fallback to regular tuples on python < 3.7
293-
if PY37:
294-
assert hasattr(result_255_columns, "_fields")
295-
else:
296-
assert not hasattr(result_255_columns, "_fields")
287+
assert hasattr(result_255_columns, "_fields")
297288

298289
def test_sequence_like_with_categorical(self):
299290

pandas/tests/frame/test_constructors.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import pytest
1111
import pytz
1212

13-
from pandas.compat import PY37, is_platform_little_endian
13+
from pandas.compat import is_platform_little_endian
1414
from pandas.compat.numpy import _np_version_under1p19
1515

1616
from pandas.core.dtypes.common import is_integer_dtype
@@ -1382,7 +1382,6 @@ def test_constructor_list_of_namedtuples(self):
13821382
result = DataFrame(tuples, columns=["y", "z"])
13831383
tm.assert_frame_equal(result, expected)
13841384

1385-
@pytest.mark.skipif(not PY37, reason="Requires Python >= 3.7")
13861385
def test_constructor_list_of_dataclasses(self):
13871386
# GH21910
13881387
from dataclasses import make_dataclass
@@ -1394,7 +1393,6 @@ def test_constructor_list_of_dataclasses(self):
13941393
result = DataFrame(datas)
13951394
tm.assert_frame_equal(result, expected)
13961395

1397-
@pytest.mark.skipif(not PY37, reason="Requires Python >= 3.7")
13981396
def test_constructor_list_of_dataclasses_with_varying_types(self):
13991397
# GH21910
14001398
from dataclasses import make_dataclass
@@ -1411,7 +1409,6 @@ def test_constructor_list_of_dataclasses_with_varying_types(self):
14111409
result = DataFrame(datas)
14121410
tm.assert_frame_equal(result, expected)
14131411

1414-
@pytest.mark.skipif(not PY37, reason="Requires Python >= 3.7")
14151412
def test_constructor_list_of_dataclasses_error_thrown(self):
14161413
# GH21910
14171414
from dataclasses import make_dataclass

0 commit comments

Comments
 (0)