Skip to content

Commit

Permalink
CLN: Use generators in builtin functions (#19989)
Browse files Browse the repository at this point in the history
  • Loading branch information
mroeschke authored and jreback committed Mar 5, 2018
1 parent 607910b commit 058a16c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pandas/_libs/parsers.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,7 @@ cdef class TextReader:
usecols = set()
if callable(self.usecols):
if self.usecols(name):
usecols = set([i])
usecols = {i}
else:
usecols = self.usecols
if self.has_usecols and not (i in usecols or
Expand Down
4 changes: 2 additions & 2 deletions pandas/_libs/tslibs/parsing.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ _DEFAULT_DATETIME = datetime(1, 1, 1).replace(hour=0, minute=0,

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

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

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

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

output_format = []
Expand Down
6 changes: 3 additions & 3 deletions pandas/compat/pickle_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ def load_reduce(self):

# try to re-encode the arguments
if getattr(self, 'encoding', None) is not None:
args = tuple([arg.encode(self.encoding)
if isinstance(arg, string_types)
else arg for arg in args])
args = tuple(arg.encode(self.encoding)
if isinstance(arg, string_types)
else arg for arg in args)
try:
stack[-1] = func(*args)
return
Expand Down
5 changes: 2 additions & 3 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,8 @@ def _dir_additions(self):
""" add the string-like attributes from the info_axis.
If info_axis is a MultiIndex, it's first level values are used.
"""
additions = set(
[c for c in self._info_axis.unique(level=0)[:100]
if isinstance(c, string_types) and isidentifier(c)])
additions = {c for c in self._info_axis.unique(level=0)[:100]
if isinstance(c, string_types) and isidentifier(c)}
return super(NDFrame, self)._dir_additions().union(additions)

@property
Expand Down
5 changes: 2 additions & 3 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -905,9 +905,8 @@ def _multi_take(self, tup):
"""
try:
o = self.obj
d = dict(
[(a, self._convert_for_reindex(t, axis=o._get_axis_number(a)))
for t, a in zip(tup, o._AXIS_ORDERS)])
d = {a: self._convert_for_reindex(t, axis=o._get_axis_number(a))
for t, a in zip(tup, o._AXIS_ORDERS)}
return o.reindex(**d)
except(KeyError, IndexingError):
raise self._exception
Expand Down

0 comments on commit 058a16c

Please sign in to comment.