From fb855da74eeb52a2ac6a0ee439456ddab6817538 Mon Sep 17 00:00:00 2001 From: Matt Roeschke Date: Wed, 18 Jul 2018 20:51:41 -0700 Subject: [PATCH] CLN:Unused Variables --- asv_bench/benchmarks/groupby.py | 2 +- pandas/_libs/internals.pyx | 2 +- pandas/_libs/ops.pyx | 4 ++-- pandas/_libs/tslibs/frequencies.pyx | 2 +- pandas/_libs/tslibs/nattype.pyx | 2 +- pandas/_libs/tslibs/offsets.pyx | 4 ++-- pandas/_libs/tslibs/period.pyx | 2 +- pandas/compat/pickle_compat.py | 3 --- pandas/core/arrays/categorical.py | 1 - pandas/core/arrays/interval.py | 4 +--- pandas/core/computation/expressions.py | 6 +++--- pandas/core/dtypes/concat.py | 6 +++--- pandas/core/dtypes/dtypes.py | 1 - pandas/core/generic.py | 5 ----- pandas/core/groupby/generic.py | 1 - pandas/core/groupby/grouper.py | 2 +- pandas/core/groupby/ops.py | 2 +- pandas/core/indexes/base.py | 9 +-------- pandas/core/indexes/category.py | 1 + pandas/core/indexes/interval.py | 3 +-- pandas/core/indexes/period.py | 1 - pandas/core/indexing.py | 6 ------ pandas/core/internals.py | 4 ---- pandas/core/nanops.py | 2 -- pandas/core/ops.py | 3 --- pandas/core/panel.py | 2 +- pandas/core/resample.py | 2 +- pandas/core/series.py | 8 +------- pandas/core/sparse/frame.py | 1 - pandas/core/sparse/series.py | 3 --- pandas/core/strings.py | 2 +- pandas/core/window.py | 4 ---- pandas/io/common.py | 4 ++-- pandas/io/formats/csvs.py | 2 +- pandas/io/formats/format.py | 2 ++ pandas/io/formats/html.py | 1 - pandas/io/formats/terminal.py | 1 - pandas/io/json/json.py | 2 ++ pandas/io/pytables.py | 5 ----- pandas/io/sas/sas_xport.py | 1 + pandas/io/sql.py | 1 - pandas/plotting/_timeseries.py | 1 - pandas/tests/frame/test_constructors.py | 1 - pandas/tests/indexing/common.py | 6 +++--- pandas/tests/io/parser/na_values.py | 6 +++--- pandas/tests/io/parser/parse_dates.py | 2 +- pandas/tseries/offsets.py | 8 ++++---- pandas/util/testing.py | 6 +++--- scripts/find_commits_touching_func.py | 2 +- 49 files changed, 48 insertions(+), 103 deletions(-) diff --git a/asv_bench/benchmarks/groupby.py b/asv_bench/benchmarks/groupby.py index 0725bbeb6c36d..b51b41614bc49 100644 --- a/asv_bench/benchmarks/groupby.py +++ b/asv_bench/benchmarks/groupby.py @@ -142,7 +142,7 @@ def time_frame_nth(self, dtype): def time_series_nth_any(self, dtype): self.df['values'].groupby(self.df['key']).nth(0, dropna='any') - def time_groupby_nth_all(self, dtype): + def time_series_nth_all(self, dtype): self.df['values'].groupby(self.df['key']).nth(0, dropna='all') def time_series_nth(self, dtype): diff --git a/pandas/_libs/internals.pyx b/pandas/_libs/internals.pyx index 2179999859dbb..96841ec21e962 100644 --- a/pandas/_libs/internals.pyx +++ b/pandas/_libs/internals.pyx @@ -390,7 +390,7 @@ def get_blkno_indexers(int64_t[:] blknos, bint group=True): start = 0 cur_blkno = blknos[start] - if group == False: + if not group: for i in range(1, n): if blknos[i] != cur_blkno: yield cur_blkno, slice(start, i) diff --git a/pandas/_libs/ops.pyx b/pandas/_libs/ops.pyx index 148018ece20e2..72a0baa763c8a 100644 --- a/pandas/_libs/ops.pyx +++ b/pandas/_libs/ops.pyx @@ -260,8 +260,8 @@ def maybe_convert_bool(ndarray[object] arr, result = np.empty(n, dtype=np.uint8) # the defaults - true_vals = set(('True', 'TRUE', 'true')) - false_vals = set(('False', 'FALSE', 'false')) + true_vals = {'True', 'TRUE', 'true'} + false_vals = {'False', 'FALSE', 'false'} if true_values is not None: true_vals = true_vals | set(true_values) diff --git a/pandas/_libs/tslibs/frequencies.pyx b/pandas/_libs/tslibs/frequencies.pyx index 7803595badee1..2caf36d24b745 100644 --- a/pandas/_libs/tslibs/frequencies.pyx +++ b/pandas/_libs/tslibs/frequencies.pyx @@ -126,7 +126,7 @@ _lite_rule_alias = { 'us': 'U', 'ns': 'N'} -_dont_uppercase = set(('MS', 'ms')) +_dont_uppercase = {'MS', 'ms'} # ---------------------------------------------------------------------- diff --git a/pandas/_libs/tslibs/nattype.pyx b/pandas/_libs/tslibs/nattype.pyx index 2fe8fab2e2e19..20b43f9d5644b 100644 --- a/pandas/_libs/tslibs/nattype.pyx +++ b/pandas/_libs/tslibs/nattype.pyx @@ -23,7 +23,7 @@ from util cimport (get_nat, # ---------------------------------------------------------------------- # Constants -nat_strings = set(['NaT', 'nat', 'NAT', 'nan', 'NaN', 'NAN']) +nat_strings = {'NaT', 'nat', 'NAT', 'nan', 'NaN', 'NAN'} cdef int64_t NPY_NAT = get_nat() iNaT = NPY_NAT # python-visible constant diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 7881529f04ed3..822c1d44457f0 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -252,12 +252,12 @@ def _validate_business_time(t_input): # --------------------------------------------------------------------- # Constructor Helpers -relativedelta_kwds = set([ +relativedelta_kwds = { 'years', 'months', 'weeks', 'days', 'year', 'month', 'week', 'day', 'weekday', 'hour', 'minute', 'second', 'microsecond', 'nanosecond', 'nanoseconds', - 'hours', 'minutes', 'seconds', 'milliseconds', 'microseconds']) + 'hours', 'minutes', 'seconds', 'milliseconds', 'microseconds'} def _determine_offset(kwds): diff --git a/pandas/_libs/tslibs/period.pyx b/pandas/_libs/tslibs/period.pyx index 59db371833957..732725975690c 100644 --- a/pandas/_libs/tslibs/period.pyx +++ b/pandas/_libs/tslibs/period.pyx @@ -1965,6 +1965,6 @@ def _validate_end_alias(how): 'START': 'S', 'FINISH': 'E', 'BEGIN': 'S', 'END': 'E'} how = how_dict.get(str(how).upper()) - if how not in set(['S', 'E']): + if how not in {'S', 'E'}: raise ValueError('How must be one of S or E') return how diff --git a/pandas/compat/pickle_compat.py b/pandas/compat/pickle_compat.py index c1a9a9fc1ed13..fb64289e5632f 100644 --- a/pandas/compat/pickle_compat.py +++ b/pandas/compat/pickle_compat.py @@ -15,9 +15,6 @@ def load_reduce(self): args = stack.pop() func = stack[-1] - if len(args) and type(args[0]) is type: - n = args[0].__name__ # noqa - try: stack[-1] = func(*args) return diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index 973a8af76bb07..9b7863224bae0 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -347,7 +347,6 @@ def __init__(self, values, categories=None, ordered=None, dtype=None, " or `ordered`.") categories = dtype.categories - ordered = dtype.ordered elif is_categorical(values): # If no "dtype" was passed, use the one from "values", but honor diff --git a/pandas/core/arrays/interval.py b/pandas/core/arrays/interval.py index c915b272aee8b..f1ef095ce54e4 100644 --- a/pandas/core/arrays/interval.py +++ b/pandas/core/arrays/interval.py @@ -25,7 +25,7 @@ from . import ExtensionArray, Categorical -_VALID_CLOSED = set(['left', 'right', 'both', 'neither']) +_VALID_CLOSED = {'left', 'right', 'both', 'neither'} _interval_shared_docs = {} _shared_docs_kwargs = dict( klass='IntervalArray', @@ -401,7 +401,6 @@ def from_tuples(cls, data, closed='right', copy=False, dtype=None): msg = ('{name}.from_tuples received an invalid ' 'item, {tpl}').format(name=name, tpl=d) raise TypeError(msg) - lhs, rhs = d left.append(lhs) right.append(rhs) @@ -815,7 +814,6 @@ def _format_data(self): summary = '[{head} ... {tail}]'.format( head=', '.join(head), tail=', '.join(tail)) else: - head = [] tail = [formatter(x) for x in self] summary = '[{tail}]'.format(tail=', '.join(tail)) diff --git a/pandas/core/computation/expressions.py b/pandas/core/computation/expressions.py index 781101f5804e6..5f59bea57fbe1 100644 --- a/pandas/core/computation/expressions.py +++ b/pandas/core/computation/expressions.py @@ -24,8 +24,8 @@ # the set of dtypes that we will allow pass to numexpr _ALLOWED_DTYPES = { - 'evaluate': set(['int64', 'int32', 'float64', 'float32', 'bool']), - 'where': set(['int64', 'float64', 'bool']) + 'evaluate': {'int64', 'int32', 'float64', 'float32', 'bool'}, + 'where': {'int64', 'float64', 'bool'} } # the minimum prod shape that we will use numexpr @@ -81,7 +81,7 @@ def _can_use_numexpr(op, op_str, a, b, dtype_check): return False dtypes |= set(s.index) elif isinstance(o, np.ndarray): - dtypes |= set([o.dtype.name]) + dtypes |= {o.dtype.name} # allowed are a superset if not len(dtypes) or _ALLOWED_DTYPES[dtype_check] >= dtypes: diff --git a/pandas/core/dtypes/concat.py b/pandas/core/dtypes/concat.py index 4a41b14cee071..2bf7d57fb36e1 100644 --- a/pandas/core/dtypes/concat.py +++ b/pandas/core/dtypes/concat.py @@ -188,8 +188,8 @@ def is_nonempty(x): typs = get_dtype_kinds(to_concat) if len(typs) != 1: - if (not len(typs - set(['i', 'u', 'f'])) or - not len(typs - set(['bool', 'i', 'u']))): + if (not len(typs - {'i', 'u', 'f'}) or + not len(typs - {'bool', 'i', 'u'})): # let numpy coerce pass else: @@ -599,7 +599,7 @@ def convert_sparse(x, axis): to_concat = [convert_sparse(x, axis) for x in to_concat] result = np.concatenate(to_concat, axis=axis) - if not len(typs - set(['sparse', 'f', 'i'])): + if not len(typs - {'sparse', 'f', 'i'}): # sparsify if inputs are sparse and dense numerics # first sparse input's fill_value and SparseIndex is used result = SparseArray(result.ravel(), fill_value=fill_values[0], diff --git a/pandas/core/dtypes/dtypes.py b/pandas/core/dtypes/dtypes.py index 57b1d81d94754..cf771a127a696 100644 --- a/pandas/core/dtypes/dtypes.py +++ b/pandas/core/dtypes/dtypes.py @@ -305,7 +305,6 @@ def _hash_categories(categories, ordered=True): # everything to a str first, which means we treat # {'1', '2'} the same as {'1', 2} # find a better solution - cat_array = np.array([hash(x) for x in categories]) hashed = hash((tuple(categories), ordered)) return hashed cat_array = hash_array(np.asarray(categories), categorize=False) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 610bcf5d1d6c4..04c7def208885 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1022,9 +1022,6 @@ def rename(self, *args, **kwargs): copy = kwargs.pop('copy', True) inplace = kwargs.pop('inplace', False) level = kwargs.pop('level', None) - axis = kwargs.pop('axis', None) - if axis is not None: - axis = self._get_axis_number(axis) if kwargs: raise TypeError('rename() got an unexpected keyword ' @@ -5206,8 +5203,6 @@ def __copy__(self, deep=True): return self.copy(deep=deep) def __deepcopy__(self, memo=None): - if memo is None: - memo = {} return self.copy(deep=True) def _convert(self, datetime=False, numeric=False, timedelta=False, diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index 169416d6f8211..3683809554e18 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -134,7 +134,6 @@ def _cython_agg_blocks(self, how, alt=None, numeric_only=True, obj = self.obj[data.items[locs]] s = groupby(obj, self.grouper) result = s.aggregate(lambda x: alt(x, axis=self.axis)) - newb = result._data.blocks[0] finally: diff --git a/pandas/core/groupby/grouper.py b/pandas/core/groupby/grouper.py index a1511b726c705..88643f0c1700a 100644 --- a/pandas/core/groupby/grouper.py +++ b/pandas/core/groupby/grouper.py @@ -481,7 +481,7 @@ def _get_grouper(obj, key=None, axis=0, level=None, sort=True, if key.key is None: return grouper, [], obj else: - return grouper, set([key.key]), obj + return grouper, {key.key}, obj # already have a BaseGrouper, just return it elif isinstance(key, BaseGrouper): diff --git a/pandas/core/groupby/ops.py b/pandas/core/groupby/ops.py index f2c55a56b119d..853927a247e50 100644 --- a/pandas/core/groupby/ops.py +++ b/pandas/core/groupby/ops.py @@ -387,6 +387,7 @@ def get_func(fname): # otherwise find dtype-specific version, falling back to object for dt in [dtype_str, 'object']: + # TODO: Should dtype_str below be replaced with dt? f = getattr(libgroupby, "%s_%s" % (fname, dtype_str), None) if f is not None: return f @@ -582,7 +583,6 @@ def _transform(self, result, values, comp_ids, transform_func, elif values.ndim > 2: for i, chunk in enumerate(values.transpose(2, 0, 1)): - chunk = chunk.squeeze() transform_func(result[:, :, i], values, comp_ids, is_datetimelike, **kwargs) else: diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 83b70baf4065b..c8fe02252dbb7 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -237,7 +237,7 @@ class Index(IndexOpsMixin, PandasObject): _engine_type = libindex.ObjectEngine - _accessors = set(['str']) + _accessors = {'str'} str = CachedAccessor("str", StringMethods) @@ -979,8 +979,6 @@ def __copy__(self, **kwargs): return self.copy(**kwargs) def __deepcopy__(self, memo=None): - if memo is None: - memo = {} return self.copy(deep=True) def _validate_names(self, name=None, names=None, deep=False): @@ -1622,11 +1620,6 @@ def is_int(v): # if we are mixed and have integers try: if is_positional and self.is_mixed(): - # TODO: i, j are not used anywhere - if start is not None: - i = self.get_loc(start) # noqa - if stop is not None: - j = self.get_loc(stop) # noqa is_positional = False except KeyError: if self.inferred_type == 'mixed-integer-float': diff --git a/pandas/core/indexes/category.py b/pandas/core/indexes/category.py index a03e478f81caf..25e737b9d35ff 100644 --- a/pandas/core/indexes/category.py +++ b/pandas/core/indexes/category.py @@ -132,6 +132,7 @@ def _create_from_codes(self, codes, categories=None, ordered=None, ordered = self.ordered if name is None: name = self.name + # TODO: ordered above is unused, should ordered be passed here? cat = Categorical.from_codes(codes, categories=categories, ordered=self.ordered) return CategoricalIndex(cat, name=name) diff --git a/pandas/core/indexes/interval.py b/pandas/core/indexes/interval.py index e92f980caf3dc..0463b19ece6f6 100644 --- a/pandas/core/indexes/interval.py +++ b/pandas/core/indexes/interval.py @@ -44,7 +44,7 @@ from pandas.core.arrays.interval import (IntervalArray, _interval_shared_docs) -_VALID_CLOSED = set(['left', 'right', 'both', 'neither']) +_VALID_CLOSED = {'left', 'right', 'both', 'neither'} _index_doc_kwargs = dict(ibase._index_doc_kwargs) _index_doc_kwargs.update( dict(klass='IntervalIndex', @@ -939,7 +939,6 @@ def _format_data(self, name=None): summary = '[{head} ... {tail}]'.format( head=', '.join(head), tail=', '.join(tail)) else: - head = [] tail = [formatter(x) for x in self] summary = '[{tail}]'.format(tail=', '.join(tail)) diff --git a/pandas/core/indexes/period.py b/pandas/core/indexes/period.py index 4d8e57820f29d..c5cb507e729f1 100644 --- a/pandas/core/indexes/period.py +++ b/pandas/core/indexes/period.py @@ -315,7 +315,6 @@ def __contains__(self, key): return True except Exception: return False - return False contains = __contains__ diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index 8ffc7548059b7..e41d22e12a539 100755 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -789,9 +789,6 @@ def _align_frame(self, indexer, df): if isinstance(indexer, tuple): aligners = [not com.is_null_slice(idx) for idx in indexer] - sum_aligners = sum(aligners) - # TODO: single_aligner is not used - single_aligner = sum_aligners == 1 # noqa idx, cols = None, None sindexers = [] @@ -865,9 +862,6 @@ def _align_frame(self, indexer, df): raise ValueError('Incompatible indexer with DataFrame') def _align_panel(self, indexer, df): - # TODO: is_frame, is_panel are unused - is_frame = self.obj.ndim == 2 # noqa - is_panel = self.obj.ndim >= 3 # noqa raise NotImplementedError("cannot set using an indexer with a Panel " "yet!") diff --git a/pandas/core/internals.py b/pandas/core/internals.py index 5a5418dcc1e7f..93ae5be344f66 100644 --- a/pandas/core/internals.py +++ b/pandas/core/internals.py @@ -1255,7 +1255,6 @@ def take_nd(self, indexer, axis, new_mgr_locs=None, fill_tuple=None): values = self.get_values() if fill_tuple is None: - fill_value = self.fill_value new_values = algos.take_nd(values, indexer, axis=axis, allow_fill=False) else: @@ -2708,7 +2707,6 @@ def _try_coerce_args(self, values, other): values_mask = isna(values) values = values.view('i8') - other_mask = False if isinstance(other, bool): raise TypeError @@ -2881,11 +2879,9 @@ def _try_coerce_args(self, values, other): values_mask = _block_shape(isna(values), ndim=self.ndim) # asi8 is a view, needs copy values = _block_shape(values.asi8, ndim=self.ndim) - other_mask = False if isinstance(other, ABCSeries): other = self._holder(other) - other_mask = isna(other) if isinstance(other, bool): raise TypeError diff --git a/pandas/core/nanops.py b/pandas/core/nanops.py index de31c6ac11c3f..8cb8e92aea4a4 100644 --- a/pandas/core/nanops.py +++ b/pandas/core/nanops.py @@ -479,7 +479,6 @@ def nanvar(values, axis=None, skipna=True, ddof=1): @disallow('M8', 'm8') def nansem(values, axis=None, skipna=True, ddof=1): - var = nanvar(values, axis, skipna, ddof=ddof) mask = isna(values) if not is_float_dtype(values.dtype): @@ -635,7 +634,6 @@ def nankurt(values, axis=None, skipna=True): adj = 3 * (count - 1) ** 2 / ((count - 2) * (count - 3)) numer = count * (count + 1) * (count - 1) * m4 denom = (count - 2) * (count - 3) * m2**2 - result = numer / denom - adj # floating point error # diff --git a/pandas/core/ops.py b/pandas/core/ops.py index bccc5a587bd83..0caf6987d6214 100644 --- a/pandas/core/ops.py +++ b/pandas/core/ops.py @@ -1743,9 +1743,6 @@ def na_op(x, y): @Appender('Wrapper for comparison method {name}'.format(name=op_name)) def f(self, other, axis=None): - # Validate the axis parameter - if axis is not None: - axis = self._get_axis_number(axis) if isinstance(other, self._constructor): return self._compare_constructor(other, na_op, try_cast=False) diff --git a/pandas/core/panel.py b/pandas/core/panel.py index 16ade3fae90a1..95ac8017ba8b4 100644 --- a/pandas/core/panel.py +++ b/pandas/core/panel.py @@ -716,7 +716,7 @@ def dropna(self, axis=0, how='any', inplace=False): values = self.values mask = notna(values) - for ax in reversed(sorted(set(range(self._AXIS_LEN)) - set([axis]))): + for ax in reversed(sorted(set(range(self._AXIS_LEN)) - {axis})): mask = mask.sum(ax) per_slice = np.prod(values.shape[:axis] + values.shape[axis + 1:]) diff --git a/pandas/core/resample.py b/pandas/core/resample.py index 32251430deec7..08bfec89a22a8 100644 --- a/pandas/core/resample.py +++ b/pandas/core/resample.py @@ -1199,7 +1199,7 @@ def __init__(self, freq='Min', closed=None, label=None, how='mean', freq = to_offset(freq) - end_types = set(['M', 'A', 'Q', 'BM', 'BA', 'BQ', 'W']) + end_types = {'M', 'A', 'Q', 'BM', 'BA', 'BQ', 'W'} rule = freq.rule_code if (rule in end_types or ('-' in rule and rule[:rule.find('-')] in end_types)): diff --git a/pandas/core/series.py b/pandas/core/series.py index 77445159129f2..dcedf0f6020b4 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -163,7 +163,7 @@ class Series(base.IndexOpsMixin, generic.NDFrame): Copy input data """ _metadata = ['name'] - _accessors = set(['dt', 'cat', 'str']) + _accessors = {'dt', 'cat', 'str'} _deprecations = generic.NDFrame._deprecations | frozenset( ['asobject', 'sortlevel', 'reshape', 'get_value', 'set_value', 'from_csv', 'valid']) @@ -2051,7 +2051,6 @@ def dot(self, other): lvals = left.values rvals = right.values else: - left = self lvals = self.values rvals = np.asarray(other) if lvals.shape[0] != rvals.shape[0]: @@ -2479,7 +2478,6 @@ def sort_values(self, axis=0, ascending=True, inplace=False, dtype: object """ inplace = validate_bool_kwarg(inplace, 'inplace') - axis = self._get_axis_number(axis) # GH 5856/5853 if inplace and self._is_cached: @@ -2651,7 +2649,6 @@ def sort_index(self, axis=0, level=None, ascending=True, inplace=False, # TODO: this can be combined with DataFrame.sort_index impl as # almost identical inplace = validate_bool_kwarg(inplace, 'inplace') - axis = self._get_axis_number(axis) index = self.index if level is not None: @@ -3072,7 +3069,6 @@ def _gotitem(self, key, ndim, subset=None): versionadded='.. versionadded:: 0.20.0', **_shared_doc_kwargs)) def aggregate(self, func, axis=0, *args, **kwargs): - axis = self._get_axis_number(axis) result, how = self._aggregate(func, *args, **kwargs) if result is None: @@ -3919,8 +3915,6 @@ def dropna(self, axis=0, inplace=False, **kwargs): raise TypeError('dropna() got an unexpected keyword ' 'argument "{0}"'.format(list(kwargs.keys())[0])) - axis = self._get_axis_number(axis or 0) - if self._can_hold_na: result = remove_na_arraylike(self) if inplace: diff --git a/pandas/core/sparse/frame.py b/pandas/core/sparse/frame.py index f7071061d07ab..818e46b0e53ee 100644 --- a/pandas/core/sparse/frame.py +++ b/pandas/core/sparse/frame.py @@ -597,7 +597,6 @@ def _combine_match_index(self, other, func, level=None): new_data[col] = func(series.values, other.values) # fill_value is a function of our operator - fill_value = None if isna(other.fill_value) or isna(self.default_fill_value): fill_value = np.nan else: diff --git a/pandas/core/sparse/series.py b/pandas/core/sparse/series.py index 96ee5b7954f45..e5bc8ad9068f2 100644 --- a/pandas/core/sparse/series.py +++ b/pandas/core/sparse/series.py @@ -624,8 +624,6 @@ def cumsum(self, axis=0, *args, **kwargs): cumsum : SparseSeries """ nv.validate_cumsum(args, kwargs) - if axis is not None: - axis = self._get_axis_number(axis) new_array = self.values.cumsum() @@ -654,7 +652,6 @@ def dropna(self, axis=0, inplace=False, **kwargs): Analogous to Series.dropna. If fill_value=NaN, returns a dense Series """ # TODO: make more efficient - axis = self._get_axis_number(axis or 0) dense_valid = self.to_dense().dropna() if inplace: raise NotImplementedError("Cannot perform inplace dropna" diff --git a/pandas/core/strings.py b/pandas/core/strings.py index e4765c00f80fd..4e68dd22eabe6 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -1078,7 +1078,7 @@ def str_get_dummies(arr, sep='|'): tags = set() for ts in arr.str.split(sep): tags.update(ts) - tags = sorted(tags - set([""])) + tags = sorted(tags - {""}) dummies = np.empty((len(arr), len(tags)), dtype=np.int64) diff --git a/pandas/core/window.py b/pandas/core/window.py index 6b6f27bcb3863..1ce6a7ec8ff14 100644 --- a/pandas/core/window.py +++ b/pandas/core/window.py @@ -773,7 +773,6 @@ class _GroupByMixin(GroupByMixin): """ provide the groupby facilities """ def __init__(self, obj, *args, **kwargs): - parent = kwargs.pop('parent', None) # noqa groupby = kwargs.pop('groupby', None) if groupby is None: groupby, obj = obj, obj.obj @@ -933,7 +932,6 @@ class _Rolling_and_Expanding(_Rolling): def count(self): blocks, obj, index = self._create_blocks() - index, indexi = self._get_index(index=index) window = self._get_window() window = min(window, len(obj)) if not self.center else window @@ -974,8 +972,6 @@ def count(self): def apply(self, func, raw=None, args=(), kwargs={}): from pandas import Series - # TODO: _level is unused? - _level = kwargs.pop('_level', None) # noqa window = self._get_window() offset = _offset(window, self.center) index, indexi = self._get_index() diff --git a/pandas/io/common.py b/pandas/io/common.py index 17dda903cdadb..4761f20154960 100644 --- a/pandas/io/common.py +++ b/pandas/io/common.py @@ -23,10 +23,10 @@ # common NA values # no longer excluding inf representations # '1.#INF','-1.#INF', '1.#INF000000', -_NA_VALUES = set([ +_NA_VALUES = { '-1.#IND', '1.#QNAN', '1.#IND', '-1.#QNAN', '#N/A N/A', '#N/A', 'N/A', 'n/a', 'NA', '#NA', 'NULL', 'null', 'NaN', '-NaN', 'nan', '-nan', '' -]) +} if compat.PY3: diff --git a/pandas/io/formats/csvs.py b/pandas/io/formats/csvs.py index 0796888554a46..a7c664cfafbff 100644 --- a/pandas/io/formats/csvs.py +++ b/pandas/io/formats/csvs.py @@ -267,7 +267,7 @@ def _save_header(self): # Write out the index line if it's not empty. # Otherwise, we will print out an extraneous # blank line between the mi and the data rows. - if encoded_labels and set(encoded_labels) != set(['']): + if encoded_labels and set(encoded_labels) != {''}: encoded_labels.extend([''] * len(columns)) writer.writerow(encoded_labels) diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index f69e4a484d177..bf3402342afc9 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -496,6 +496,8 @@ def _chk_truncate(self): self.tr_col_num = col_num if truncate_v: if max_rows_adj == 0: + # TODO: should the next condition be an elif? row_num gets + # overwritten in the next block row_num = len(frame) if max_rows_adj == 1: row_num = max_rows diff --git a/pandas/io/formats/html.py b/pandas/io/formats/html.py index 20be903f54967..3ea5cb95b9c5a 100644 --- a/pandas/io/formats/html.py +++ b/pandas/io/formats/html.py @@ -222,7 +222,6 @@ def _column_header(): return row self.write('', indent) - row = [] indent += self.indent_delta diff --git a/pandas/io/formats/terminal.py b/pandas/io/formats/terminal.py index 52262ea05bf96..9056aa89da411 100644 --- a/pandas/io/formats/terminal.py +++ b/pandas/io/formats/terminal.py @@ -67,7 +67,6 @@ def is_terminal(): def _get_terminal_size_windows(): - res = None try: from ctypes import windll, create_string_buffer diff --git a/pandas/io/json/json.py b/pandas/io/json/json.py index 3ec5e8d9be955..6da97c297486b 100644 --- a/pandas/io/json/json.py +++ b/pandas/io/json/json.py @@ -547,6 +547,8 @@ def _get_object_parser(self, json): if typ == 'series' or obj is None: if not isinstance(dtype, bool): + # TODO: dtype is unused. This is probably supposed to be + # kwargs.update({'dtype' : dtype}) dtype = dict(data=dtype) obj = SeriesParser(json, **kwargs).parse() diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index f2d6fe01e0573..3ac4e29c70110 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -2819,7 +2819,6 @@ def read_index_legacy(self, key, start=None, stop=None): class LegacySeriesFixed(LegacyFixed): def read(self, **kwargs): - kwargs = self.validate_read(kwargs) index = self.read_index_legacy('index') values = self.read_array('values') return Series(values, index=index) @@ -2828,7 +2827,6 @@ def read(self, **kwargs): class LegacyFrameFixed(LegacyFixed): def read(self, **kwargs): - kwargs = self.validate_read(kwargs) index = self.read_index_legacy('index') columns = self.read_index_legacy('columns') values = self.read_array('values') @@ -2877,7 +2875,6 @@ class SparseSeriesFixed(SparseFixed): attributes = ['name', 'fill_value', 'kind'] def read(self, **kwargs): - kwargs = self.validate_read(kwargs) index = self.read_index('index') sp_values = self.read_array('sp_values') sp_index = self.read_index('sp_index') @@ -2901,7 +2898,6 @@ class SparseFrameFixed(SparseFixed): attributes = ['default_kind', 'default_fill_value'] def read(self, **kwargs): - kwargs = self.validate_read(kwargs) columns = self.read_index('columns') sdict = {} for c in columns: @@ -2967,7 +2963,6 @@ def shape(self): def read(self, start=None, stop=None, **kwargs): # start, stop applied to rows, so 0th axis only - kwargs = self.validate_read(kwargs) select_axis = self.obj_type()._get_block_manager_axis(0) axes = [] diff --git a/pandas/io/sas/sas_xport.py b/pandas/io/sas/sas_xport.py index 52b25898fc67e..87be54a1934ba 100644 --- a/pandas/io/sas/sas_xport.py +++ b/pandas/io/sas/sas_xport.py @@ -183,6 +183,7 @@ def _parse_float_vec(vec): # Get the second half of the ibm number into the second half of # the ieee number + # TODO: This value is unused ieee2 = xport2 # The fraction bit to the left of the binary point in the ieee diff --git a/pandas/io/sql.py b/pandas/io/sql.py index a582d32741ae9..e9ac4ea0972cb 100644 --- a/pandas/io/sql.py +++ b/pandas/io/sql.py @@ -845,7 +845,6 @@ def _sqlalchemy_type(self, col): if col_type == 'datetime64' or col_type == 'datetime': try: - tz = col.tzinfo # noqa return DateTime(timezone=True) except: return DateTime diff --git a/pandas/plotting/_timeseries.py b/pandas/plotting/_timeseries.py index 0522d7e721b65..96e7532747c78 100644 --- a/pandas/plotting/_timeseries.py +++ b/pandas/plotting/_timeseries.py @@ -86,7 +86,6 @@ def _maybe_resample(series, ax, kwargs): freq = ax_freq elif frequencies.is_subperiod(freq, ax_freq) or _is_sub(freq, ax_freq): _upsample_others(ax, freq, kwargs) - ax_freq = freq else: # pragma: no cover raise ValueError('Incompatible frequency conversion') return freq, series diff --git a/pandas/tests/frame/test_constructors.py b/pandas/tests/frame/test_constructors.py index bef38288ff3a5..0b74867461eca 100644 --- a/pandas/tests/frame/test_constructors.py +++ b/pandas/tests/frame/test_constructors.py @@ -900,7 +900,6 @@ def test_constructor_empty_list(self): # Empty generator: list(empty_gen()) == [] def empty_gen(): return - yield df = DataFrame(empty_gen(), columns=['A', 'B']) tm.assert_frame_equal(df, expected) diff --git a/pandas/tests/indexing/common.py b/pandas/tests/indexing/common.py index a77c170221bea..cdd1fafe7cfaa 100644 --- a/pandas/tests/indexing/common.py +++ b/pandas/tests/indexing/common.py @@ -28,9 +28,9 @@ def _axify(obj, key, axis): class Base(object): """ indexing comprehensive base class """ - _objs = set(['series', 'frame', 'panel']) - _typs = set(['ints', 'uints', 'labels', 'mixed', - 'ts', 'floats', 'empty', 'ts_rev', 'multi']) + _objs = {'series', 'frame', 'panel'} + _typs = {'ints', 'uints', 'labels', 'mixed', + 'ts', 'floats', 'empty', 'ts_rev', 'multi'} def setup_method(self, method): diff --git a/pandas/tests/io/parser/na_values.py b/pandas/tests/io/parser/na_values.py index d2c3f82e95c4d..2a43a590cbe6b 100644 --- a/pandas/tests/io/parser/na_values.py +++ b/pandas/tests/io/parser/na_values.py @@ -69,9 +69,9 @@ def test_non_string_na_values(self): tm.assert_frame_equal(out, expected) def test_default_na_values(self): - _NA_VALUES = set(['-1.#IND', '1.#QNAN', '1.#IND', '-1.#QNAN', - '#N/A', 'N/A', 'n/a', 'NA', '#NA', 'NULL', 'null', - 'NaN', 'nan', '-NaN', '-nan', '#N/A N/A', '']) + _NA_VALUES = {'-1.#IND', '1.#QNAN', '1.#IND', '-1.#QNAN', + '#N/A', 'N/A', 'n/a', 'NA', '#NA', 'NULL', 'null', + 'NaN', 'nan', '-NaN', '-nan', '#N/A N/A', ''} assert _NA_VALUES == com._NA_VALUES nv = len(_NA_VALUES) diff --git a/pandas/tests/io/parser/parse_dates.py b/pandas/tests/io/parser/parse_dates.py index 919b357f14236..1bf055854de88 100644 --- a/pandas/tests/io/parser/parse_dates.py +++ b/pandas/tests/io/parser/parse_dates.py @@ -455,7 +455,7 @@ def test_read_with_parse_dates_invalid_type(self): self.read_csv, StringIO(data), parse_dates=np.array([4, 5])) tm.assert_raises_regex(TypeError, errmsg, self.read_csv, - StringIO(data), parse_dates=set([1, 3, 3])) + StringIO(data), parse_dates={1, 3, 3}) def test_parse_dates_empty_string(self): # see gh-2263 diff --git a/pandas/tseries/offsets.py b/pandas/tseries/offsets.py index 5d076bf33a8ac..2d36e50fd361f 100644 --- a/pandas/tseries/offsets.py +++ b/pandas/tseries/offsets.py @@ -226,9 +226,9 @@ def apply_index(self, i): "implementation".format( name=self.__class__.__name__)) kwds = self.kwds - relativedelta_fast = set(['years', 'months', 'weeks', - 'days', 'hours', 'minutes', - 'seconds', 'microseconds']) + relativedelta_fast = {'years', 'months', 'weeks', + 'days', 'hours', 'minutes', + 'seconds', 'microseconds'} # relativedelta/_offset path only valid for base DateOffset if (self._use_relativedelta and set(kwds).issubset(relativedelta_fast)): @@ -270,7 +270,7 @@ def isAnchored(self): # set of attributes on each object rather than the existing behavior of # iterating over internal ``__dict__`` def _repr_attrs(self): - exclude = set(['n', 'inc', 'normalize']) + exclude = {'n', 'inc', 'normalize'} attrs = [] for attr in sorted(self.__dict__): if attr.startswith('_') or attr == 'kwds': diff --git a/pandas/util/testing.py b/pandas/util/testing.py index 9697c991122dd..50989ae68cc93 100644 --- a/pandas/util/testing.py +++ b/pandas/util/testing.py @@ -909,8 +909,8 @@ def repr_class(x): if exact == 'equiv': if type(left) != type(right): # allow equivalence of Int64Index/RangeIndex - types = set([type(left).__name__, type(right).__name__]) - if len(types - set(['Int64Index', 'RangeIndex'])): + types = {type(left).__name__, type(right).__name__} + if len(types - {'Int64Index', 'RangeIndex'}): msg = '{obj} classes are not equivalent'.format(obj=obj) raise_assert_detail(obj, msg, repr_class(left), repr_class(right)) @@ -2317,7 +2317,7 @@ def wrapper(*args, **kwargs): raise else: skip("Skipping test due to lack of connectivity" - " and error {error}".format(e)) + " and error {error}".format(error=e)) return wrapper diff --git a/scripts/find_commits_touching_func.py b/scripts/find_commits_touching_func.py index 29eb4161718ff..10035aeeec94c 100755 --- a/scripts/find_commits_touching_func.py +++ b/scripts/find_commits_touching_func.py @@ -135,7 +135,7 @@ def search(defname, head_commit="HEAD"): # seed with hits from q allhits = set(get_hits(defname, files=files)) - q = set([HEAD]) + q = {HEAD} try: while q: h = q.pop()