Skip to content

Commit 6e0f9a9

Browse files
jschendeljreback
authored andcommitted
CLN: Remove redundant definitions in pandas.compat (filter, map, range, etc.) (#25845)
1 parent 2b67692 commit 6e0f9a9

File tree

136 files changed

+139
-235
lines changed

Some content is hidden

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

136 files changed

+139
-235
lines changed

pandas/_libs/parsers.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ cdef class TextReader:
698698

699699
if ptr == NULL:
700700
if not os.path.exists(source):
701-
raise compat.FileNotFoundError(
701+
raise FileNotFoundError(
702702
ENOENT,
703703
'File {source} does not exist'.format(source=source),
704704
source)

pandas/compat/__init__.py

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Cross-compatible functions for Python 2 and 3.
66
77
Key items to import for 2/3 compatible code:
8-
* iterators: range(), map(), zip(), filter(), reduce()
8+
* iterators: reduce()
99
* lists: lrange(), lmap(), lzip(), lfilter()
1010
* unicode: u() [no unicode builtin in Python 3]
1111
* longs: long (int in Python 3)
@@ -107,19 +107,11 @@ def get_range_parameters(data):
107107
return data.start, data.stop, data.step
108108

109109
# have to explicitly put builtins into the namespace
110-
range = range
111-
map = map
112-
zip = zip
113-
filter = filter
114110
intern = sys.intern
115111
reduce = functools.reduce
116112
long = int
117113
unichr = chr
118114

119-
# This was introduced in Python 3.3, but we don't support
120-
# Python 3.x < 3.5, so checking PY3 is safe.
121-
FileNotFoundError = FileNotFoundError
122-
123115
# list-producing versions of the major Python iterating functions
124116
def lrange(*args, **kwargs):
125117
return list(range(*args, **kwargs))
@@ -148,8 +140,6 @@ def lfilter(*args, **kwargs):
148140
# Python 2
149141
_name_re = re.compile(r"[a-zA-Z_][a-zA-Z0-9_]*$")
150142

151-
FileNotFoundError = IOError
152-
153143
def isidentifier(s, dotted=False):
154144
return bool(_name_re.match(s))
155145

@@ -181,11 +171,7 @@ def get_range_parameters(data):
181171
return start, stop, step
182172

183173
# import iterator versions of these functions
184-
range = xrange
185174
intern = intern
186-
zip = itertools.izip
187-
filter = itertools.ifilter
188-
map = itertools.imap
189175
reduce = reduce
190176
long = long
191177
unichr = unichr
@@ -217,7 +203,6 @@ def iterkeys(obj, **kw):
217203
def itervalues(obj, **kw):
218204
return obj.itervalues(**kw)
219205

220-
next = lambda it: it.next()
221206
else:
222207
def iteritems(obj, **kw):
223208
return iter(obj.items(**kw))
@@ -228,8 +213,6 @@ def iterkeys(obj, **kw):
228213
def itervalues(obj, **kw):
229214
return iter(obj.values(**kw))
230215

231-
next = next
232-
233216

234217
def bind_method(cls, name, func):
235218
"""Bind a method to class, python 2 and python 3 compatible.
@@ -315,9 +298,6 @@ def set_function_name(f, name, cls):
315298
name=name)
316299
f.__module__ = cls.__module__
317300
return f
318-
319-
ResourceWarning = ResourceWarning
320-
321301
else:
322302
string_types = basestring,
323303
integer_types = (int, long)
@@ -373,9 +353,6 @@ def set_function_name(f, name, cls):
373353
f.__name__ = name
374354
return f
375355

376-
class ResourceWarning(Warning):
377-
pass
378-
379356
string_and_binary_types = string_types + (binary_type,)
380357

381358

pandas/core/arrays/integer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import numpy as np
66

77
from pandas._libs import lib
8-
from pandas.compat import range, set_function_name, string_types
8+
from pandas.compat import set_function_name, string_types
99
from pandas.util._decorators import cache_readonly
1010

1111
from pandas.core.dtypes.base import ExtensionDtype

pandas/core/arrays/period.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -934,14 +934,14 @@ def _range_from_fields(year=None, month=None, quarter=None, day=None,
934934
raise AssertionError("base must equal FR_QTR")
935935

936936
year, quarter = _make_field_arrays(year, quarter)
937-
for y, q in compat.zip(year, quarter):
937+
for y, q in zip(year, quarter):
938938
y, m = libperiod.quarter_to_myear(y, q, freq)
939939
val = libperiod.period_ordinal(y, m, 1, 1, 1, 1, 0, 0, base)
940940
ordinals.append(val)
941941
else:
942942
base, mult = libfrequencies.get_freq_code(freq)
943943
arrays = _make_field_arrays(year, month, day, hour, minute, second)
944-
for y, mth, d, h, mn, s in compat.zip(*arrays):
944+
for y, mth, d, h, mn, s in zip(*arrays):
945945
ordinals.append(libperiod.period_ordinal(
946946
y, mth, d, h, mn, s, 0, 0, base))
947947

pandas/core/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import pandas._libs.lib as lib
1111
import pandas.compat as compat
12-
from pandas.compat import PYPY, builtins, map, range
12+
from pandas.compat import PYPY, builtins
1313
from pandas.compat.numpy import function as nv
1414
from pandas.errors import AbstractMethodError
1515
from pandas.util._decorators import Appender, Substitution, cache_readonly

pandas/core/computation/align.py

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

77
import numpy as np
88

9-
from pandas.compat import range, zip
109
from pandas.errors import PerformanceWarning
1110

1211
import pandas as pd

pandas/core/computation/engines.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
import abc
66

7-
from pandas.compat import map
8-
97
from pandas import compat
108
from pandas.core.computation.align import _align, _reconstruct_object
119
from pandas.core.computation.ops import (

pandas/core/computation/expr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import numpy as np
1111

12-
from pandas.compat import StringIO, lmap, map, reduce, string_types, zip
12+
from pandas.compat import StringIO, lmap, reduce, string_types
1313

1414
import pandas as pd
1515
from pandas import compat

pandas/core/computation/scope.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import numpy as np
1313

1414
from pandas._libs.tslibs import Timestamp
15-
from pandas.compat import DeepChainMap, StringIO, map
15+
from pandas.compat import DeepChainMap, StringIO
1616

1717
from pandas.core.base import StringMixin
1818
import pandas.core.computation as compu

pandas/core/frame.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
validate_axis_style_args)
3434

3535
from pandas import compat
36-
from pandas.compat import (range, map, zip, lmap, lzip, StringIO, u,
37-
PY36, raise_with_traceback, Iterator,
38-
string_and_binary_types)
36+
from pandas.compat import (
37+
PY36, Iterator, StringIO, lmap, lzip, raise_with_traceback,
38+
string_and_binary_types, u)
3939
from pandas.compat.numpy import function as nv
4040
from pandas.core.dtypes.cast import (
4141
maybe_upcast,

0 commit comments

Comments
 (0)