Skip to content

Commit 058a16c

Browse files
mroeschkejreback
authored andcommitted
CLN: Use generators in builtin functions (#19989)
1 parent 607910b commit 058a16c

File tree

5 files changed

+10
-12
lines changed

5 files changed

+10
-12
lines changed

pandas/_libs/parsers.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,7 @@ cdef class TextReader:
10451045
usecols = set()
10461046
if callable(self.usecols):
10471047
if self.usecols(name):
1048-
usecols = set([i])
1048+
usecols = {i}
10491049
else:
10501050
usecols = self.usecols
10511051
if self.has_usecols and not (i in usecols or

pandas/_libs/tslibs/parsing.pyx

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ _DEFAULT_DATETIME = datetime(1, 1, 1).replace(hour=0, minute=0,
5757

5858
cdef object _TIMEPAT = re.compile(r'^([01]?[0-9]|2[0-3]):([0-5][0-9])')
5959

60-
cdef set _not_datelike_strings = set(['a', 'A', 'm', 'M', 'p', 'P', 't', 'T'])
60+
cdef set _not_datelike_strings = {'a', 'A', 'm', 'M', 'p', 'P', 't', 'T'}
6161

6262
NAT_SENTINEL = object()
6363
# This allows us to reference NaT without having to import it
@@ -651,7 +651,7 @@ def _guess_datetime_format(dt_str, dayfirst=False, dt_str_parse=du_parse,
651651
break
652652

653653
# Only consider it a valid guess if we have a year, month and day
654-
if len(set(['year', 'month', 'day']) & found_attrs) != 3:
654+
if len({'year', 'month', 'day'} & found_attrs) != 3:
655655
return None
656656

657657
output_format = []

pandas/compat/pickle_compat.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ def load_reduce(self):
3838

3939
# try to re-encode the arguments
4040
if getattr(self, 'encoding', None) is not None:
41-
args = tuple([arg.encode(self.encoding)
42-
if isinstance(arg, string_types)
43-
else arg for arg in args])
41+
args = tuple(arg.encode(self.encoding)
42+
if isinstance(arg, string_types)
43+
else arg for arg in args)
4444
try:
4545
stack[-1] = func(*args)
4646
return

pandas/core/generic.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,8 @@ def _dir_additions(self):
212212
""" add the string-like attributes from the info_axis.
213213
If info_axis is a MultiIndex, it's first level values are used.
214214
"""
215-
additions = set(
216-
[c for c in self._info_axis.unique(level=0)[:100]
217-
if isinstance(c, string_types) and isidentifier(c)])
215+
additions = {c for c in self._info_axis.unique(level=0)[:100]
216+
if isinstance(c, string_types) and isidentifier(c)}
218217
return super(NDFrame, self)._dir_additions().union(additions)
219218

220219
@property

pandas/core/indexing.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -905,9 +905,8 @@ def _multi_take(self, tup):
905905
"""
906906
try:
907907
o = self.obj
908-
d = dict(
909-
[(a, self._convert_for_reindex(t, axis=o._get_axis_number(a)))
910-
for t, a in zip(tup, o._AXIS_ORDERS)])
908+
d = {a: self._convert_for_reindex(t, axis=o._get_axis_number(a))
909+
for t, a in zip(tup, o._AXIS_ORDERS)}
911910
return o.reindex(**d)
912911
except(KeyError, IndexingError):
913912
raise self._exception

0 commit comments

Comments
 (0)