Skip to content

Commit 7ce9c79

Browse files
Removing all unneeded PY36 checks from code (tests pending)
1 parent 1f2805b commit 7ce9c79

File tree

10 files changed

+12
-68
lines changed

10 files changed

+12
-68
lines changed

pandas/_libs/tslibs/timestamps.pyx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ from pandas._libs.tslibs.tzconversion import (
3636
# Constants
3737
_zero_time = datetime_time(0, 0)
3838
_no_input = object()
39-
PY36 = sys.version_info >= (3, 6)
4039

4140
# ----------------------------------------------------------------------
4241

@@ -982,9 +981,8 @@ default 'raise'
982981
else:
983982
kwargs = {'year': dts.year, 'month': dts.month, 'day': dts.day,
984983
'hour': dts.hour, 'minute': dts.min, 'second': dts.sec,
985-
'microsecond': dts.us, 'tzinfo': _tzinfo}
986-
if PY36:
987-
kwargs['fold'] = fold
984+
'microsecond': dts.us, 'tzinfo': _tzinfo,
985+
'fold': fold}
988986
ts_input = datetime(**kwargs)
989987

990988
ts = convert_datetime_to_tsobject(ts_input, _tzinfo)

pandas/compat/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import sys
1313
import warnings
1414

15-
PY36 = sys.version_info >= (3, 6)
1615
PY37 = sys.version_info >= (3, 7)
1716
PY38 = sys.version_info >= (3, 8)
1817
PYPY = platform.python_implementation() == "PyPy"

pandas/core/common.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"""
66

77
import collections
8-
from collections import OrderedDict, abc
8+
from collections import abc
99
from datetime import datetime, timedelta
1010
from functools import partial
1111
import inspect
@@ -14,7 +14,6 @@
1414
import numpy as np
1515

1616
from pandas._libs import lib, tslibs
17-
from pandas.compat import PY36
1817

1918
from pandas.core.dtypes.cast import construct_1d_object_array_from_listlike
2019
from pandas.core.dtypes.common import (
@@ -216,13 +215,7 @@ def try_sort(iterable):
216215

217216

218217
def dict_keys_to_ordered_list(mapping):
219-
# when pandas drops support for Python < 3.6, this function
220-
# can be replaced by a simple list(mapping.keys())
221-
if PY36 or isinstance(mapping, OrderedDict):
222-
keys = list(mapping.keys())
223-
else:
224-
keys = try_sort(mapping)
225-
return keys
218+
return list(mapping.keys())
226219

227220

228221
def asarray_tuplesafe(values, dtype=None):

pandas/core/dtypes/common.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from pandas._libs import algos, lib
88
from pandas._libs.tslibs import conversion
9-
from pandas.compat import PY36
109

1110
from pandas.core.dtypes.dtypes import (
1211
CategoricalDtype,
@@ -1278,11 +1277,7 @@ def _is_unorderable_exception(e: TypeError) -> bool:
12781277
boolean
12791278
Whether or not the exception raised is an unorderable exception.
12801279
"""
1281-
1282-
if PY36:
1283-
return "'>' not supported between instances of" in str(e)
1284-
1285-
return "unorderable" in str(e)
1280+
return "'>' not supported between instances of" in str(e)
12861281

12871282

12881283
def is_numeric_v_string_like(a, b):

pandas/core/frame.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
from pandas._config import get_option
3535

3636
from pandas._libs import algos as libalgos, lib
37-
from pandas.compat import PY36
3837
from pandas.compat.numpy import function as nv
3938
from pandas.util._decorators import (
4039
Appender,
@@ -3548,21 +3547,8 @@ def assign(self, **kwargs):
35483547
"""
35493548
data = self.copy()
35503549

3551-
# >= 3.6 preserve order of kwargs
3552-
if PY36:
3553-
for k, v in kwargs.items():
3554-
data[k] = com.apply_if_callable(v, data)
3555-
else:
3556-
# <= 3.5: do all calculations first...
3557-
results = OrderedDict()
3558-
for k, v in kwargs.items():
3559-
results[k] = com.apply_if_callable(v, data)
3560-
3561-
# <= 3.5 and earlier
3562-
results = sorted(results.items())
3563-
# ... and then assign
3564-
for k, v in results:
3565-
data[k] = v
3550+
for k, v in kwargs.items():
3551+
data[k] = com.apply_if_callable(v, data)
35663552
return data
35673553

35683554
def _sanitize_column(self, key, value, broadcast=True):

pandas/core/generic.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,7 @@ class NDFrame(PandasObject, SelectionMixin):
192192
_data = None # type: BlockManager
193193

194194
if TYPE_CHECKING:
195-
# TODO(PY36): replace with _attrs : Dict[Hashable, Any]
196-
# We need the TYPE_CHECKING, because _attrs is not a class attribute
197-
# and Py35 doesn't support the new syntax.
198-
_attrs = {} # type: Dict[Optional[Hashable], Any]
195+
_attrs = {} # type: Dict[Hashable, Any]
199196

200197
# ----------------------------------------------------------------------
201198
# Constructors

pandas/core/groupby/generic.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import numpy as np
2929

3030
from pandas._libs import Timestamp, lib
31-
from pandas.compat import PY36
3231
from pandas.util._decorators import Appender, Substitution
3332

3433
from pandas.core.dtypes.cast import (
@@ -233,10 +232,6 @@ def aggregate(self, func=None, *args, **kwargs):
233232
no_arg_message = "Must provide 'func' or named aggregation **kwargs."
234233
if relabeling:
235234
columns = list(kwargs)
236-
if not PY36:
237-
# sort for 3.5 and earlier
238-
columns = list(sorted(columns))
239-
240235
func = [kwargs[col] for col in columns]
241236
kwargs = {}
242237
if not columns:
@@ -1814,9 +1809,6 @@ def _normalize_keyword_aggregation(kwargs):
18141809
>>> _normalize_keyword_aggregation({'output': ('input', 'sum')})
18151810
(OrderedDict([('input', ['sum'])]), ('output',), [('input', 'sum')])
18161811
"""
1817-
if not PY36:
1818-
kwargs = OrderedDict(sorted(kwargs.items()))
1819-
18201812
# Normalize the aggregation functions as Dict[column, List[func]],
18211813
# process normally, then fixup the names.
18221814
# TODO(Py35): When we drop python 3.5, change this to

pandas/core/internals/construction.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
import numpy.ma as ma
99

1010
from pandas._libs import lib
11-
import pandas.compat as compat
12-
from pandas.compat import PY36
1311

1412
from pandas.core.dtypes.cast import (
1513
construct_1d_arraylike_from_scalar,
@@ -331,16 +329,13 @@ def extract_index(data):
331329
have_raw_arrays = False
332330
have_series = False
333331
have_dicts = False
334-
have_ordered = False
335332

336333
for val in data:
337334
if isinstance(val, ABCSeries):
338335
have_series = True
339336
indexes.append(val.index)
340337
elif isinstance(val, dict):
341338
have_dicts = True
342-
if isinstance(val, OrderedDict):
343-
have_ordered = True
344339
indexes.append(list(val.keys()))
345340
elif is_list_like(val) and getattr(val, "ndim", 1) == 1:
346341
have_raw_arrays = True
@@ -352,7 +347,7 @@ def extract_index(data):
352347
if have_series:
353348
index = _union_indexes(indexes)
354349
elif have_dicts:
355-
index = _union_indexes(indexes, sort=not (compat.PY36 or have_ordered))
350+
index = _union_indexes(indexes, sort=False)
356351

357352
if have_raw_arrays:
358353
lengths = list(set(raw_lengths))
@@ -550,7 +545,7 @@ def _list_of_dict_to_arrays(data, columns, coerce_float=False, dtype=None):
550545
"""
551546
if columns is None:
552547
gen = (list(x.keys()) for x in data)
553-
types = (dict, OrderedDict) if PY36 else OrderedDict
548+
types = (dict, OrderedDict)
554549
sort = not any(isinstance(d, types) for d in data)
555550
columns = lib.fast_unique_multiple_list_gen(gen, sort=sort)
556551

pandas/core/series.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""
22
Data structure for 1-dimensional cross-sectional and time series data
33
"""
4-
from collections import OrderedDict
54
from io import StringIO
65
from shutil import get_terminal_size
76
from textwrap import dedent
@@ -13,7 +12,6 @@
1312
from pandas._config import get_option
1413

1514
from pandas._libs import index as libindex, lib, reshape, tslibs
16-
from pandas.compat import PY36
1715
from pandas.compat.numpy import function as nv
1816
from pandas.util._decorators import Appender, Substitution, deprecate
1917
from pandas.util._validators import validate_bool_kwarg, validate_percentile
@@ -362,13 +360,6 @@ def _init_dict(self, data, index=None, dtype=None):
362360
# Now we just make sure the order is respected, if any
363361
if data and index is not None:
364362
s = s.reindex(index, copy=False)
365-
elif not PY36 and not isinstance(data, OrderedDict) and data:
366-
# Need the `and data` to avoid sorting Series(None, index=[...])
367-
# since that isn't really dict-like
368-
try:
369-
s = s.sort_index()
370-
except TypeError:
371-
pass
372363
return s._data, s.index
373364

374365
@classmethod

pandas/io/pickle.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import pickle
33
import warnings
44

5-
from pandas.compat import PY36, pickle_compat as pc
5+
from pandas.compat import pickle_compat as pc
66

77
from pandas.io.common import _get_handle, _stringify_path
88

@@ -140,9 +140,7 @@ def read_pickle(path, compression="infer"):
140140
# 1) try standard library Pickle
141141
# 2) try pickle_compat (older pandas version) to handle subclass changes
142142

143-
excs_to_catch = (AttributeError, ImportError)
144-
if PY36:
145-
excs_to_catch += (ModuleNotFoundError,)
143+
excs_to_catch = (AttributeError, ImportError, ModuleNotFoundError)
146144

147145
try:
148146
with warnings.catch_warnings(record=True):

0 commit comments

Comments
 (0)