diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index 4584e4694cdc5..204e800b932a9 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -348,7 +348,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 5ecc79e030f56..ad01d4ec9b3ca 100644 --- a/pandas/core/arrays/interval.py +++ b/pandas/core/arrays/interval.py @@ -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) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 376700f1418f6..edf341ae2898f 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1084,7 +1084,8 @@ def rename(self, *args, **kwargs): level = kwargs.pop('level', None) axis = kwargs.pop('axis', None) if axis is not None: - axis = self._get_axis_number(axis) + # Validate the axis + self._get_axis_number(axis) if kwargs: raise TypeError('rename() got an unexpected keyword ' @@ -5299,6 +5300,12 @@ def __copy__(self, deep=True): return self.copy(deep=deep) def __deepcopy__(self, memo=None): + """ + Parameters + ---------- + memo, default None + Standard signature. Unused + """ if memo is None: memo = {} return self.copy(deep=True) diff --git a/pandas/core/groupby/ops.py b/pandas/core/groupby/ops.py index 38ac144ac6c95..ba04ff3a3d3ee 100644 --- a/pandas/core/groupby/ops.py +++ b/pandas/core/groupby/ops.py @@ -582,7 +582,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 f09fe8c8abdcf..8ad058c001bba 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -993,6 +993,12 @@ def __copy__(self, **kwargs): return self.copy(**kwargs) def __deepcopy__(self, memo=None): + """ + Parameters + ---------- + memo, default None + Standard signature. Unused + """ if memo is None: memo = {} return self.copy(deep=True) diff --git a/pandas/core/indexes/category.py b/pandas/core/indexes/category.py index d76a7ef00f625..ab180a13ab4f3 100644 --- a/pandas/core/indexes/category.py +++ b/pandas/core/indexes/category.py @@ -133,7 +133,7 @@ def _create_from_codes(self, codes, categories=None, ordered=None, if name is None: name = self.name cat = Categorical.from_codes(codes, categories=categories, - ordered=self.ordered) + ordered=ordered) return CategoricalIndex(cat, name=name) @classmethod diff --git a/pandas/core/indexes/interval.py b/pandas/core/indexes/interval.py index 246bd3d541b72..0b467760d82d9 100644 --- a/pandas/core/indexes/interval.py +++ b/pandas/core/indexes/interval.py @@ -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/internals/blocks.py b/pandas/core/internals/blocks.py index ffa2267dd6877..0f3ffb8055330 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -1248,7 +1248,7 @@ def take_nd(self, indexer, axis, new_mgr_locs=None, fill_tuple=None): if fill_tuple is None: fill_value = self.fill_value new_values = algos.take_nd(values, indexer, axis=axis, - allow_fill=False) + allow_fill=False, fill_value=fill_value) else: fill_value = fill_tuple[0] new_values = algos.take_nd(values, indexer, axis=axis, @@ -2699,7 +2699,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 @@ -2872,11 +2871,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 32fd70bcf654d..f44fb4f6e9e14 100644 --- a/pandas/core/nanops.py +++ b/pandas/core/nanops.py @@ -479,7 +479,9 @@ 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) + # This checks if non-numeric-like data is passed with numeric_only=False + # and raises a TypeError otherwise + nanvar(values, axis, skipna, ddof=ddof) mask = isna(values) if not is_float_dtype(values.dtype): @@ -635,7 +637,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/series.py b/pandas/core/series.py index 08b77c505463e..8f9fe5ee516e6 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2052,7 +2052,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]: @@ -2480,7 +2479,8 @@ def sort_values(self, axis=0, ascending=True, inplace=False, dtype: object """ inplace = validate_bool_kwarg(inplace, 'inplace') - axis = self._get_axis_number(axis) + # Validate the axis parameter + self._get_axis_number(axis) # GH 5856/5853 if inplace and self._is_cached: @@ -2652,7 +2652,8 @@ 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) + # Validate the axis parameter + self._get_axis_number(axis) index = self.index if level is not None: @@ -3073,7 +3074,8 @@ 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) + # Validate the axis parameter + self._get_axis_number(axis) result, how = self._aggregate(func, *args, **kwargs) if result is None: @@ -3919,8 +3921,8 @@ def dropna(self, axis=0, inplace=False, **kwargs): if kwargs: raise TypeError('dropna() got an unexpected keyword ' 'argument "{0}"'.format(list(kwargs.keys())[0])) - - axis = self._get_axis_number(axis or 0) + # Validate the axis parameter + self._get_axis_number(axis or 0) if self._can_hold_na: result = remove_na_arraylike(self) diff --git a/pandas/core/sparse/frame.py b/pandas/core/sparse/frame.py index 5cb9f4744cc58..58e3001bcfe6a 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/window.py b/pandas/core/window.py index f3b4aaa74ec6b..eed0e97f30dc9 100644 --- a/pandas/core/window.py +++ b/pandas/core/window.py @@ -933,7 +933,8 @@ class _Rolling_and_Expanding(_Rolling): def count(self): blocks, obj, index = self._create_blocks() - index, indexi = self._get_index(index=index) + # Validate the index + self._get_index(index=index) window = self._get_window() window = min(window, len(obj)) if not self.center else window diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index f69e4a484d177..c6ca59aa08bf9 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -495,8 +495,6 @@ def _chk_truncate(self): frame.iloc[:, -col_num:]), axis=1) self.tr_col_num = col_num if truncate_v: - if max_rows_adj == 0: - row_num = len(frame) if max_rows_adj == 1: row_num = max_rows frame = frame.iloc[: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..dcd6f2cf4a718 100644 --- a/pandas/io/formats/terminal.py +++ b/pandas/io/formats/terminal.py @@ -67,7 +67,7 @@ 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..629e00ebfa7d0 100644 --- a/pandas/io/json/json.py +++ b/pandas/io/json/json.py @@ -547,7 +547,7 @@ def _get_object_parser(self, json): if typ == 'series' or obj is None: if not isinstance(dtype, bool): - dtype = dict(data=dtype) + kwargs['dtype'] = dtype obj = SeriesParser(json, **kwargs).parse() return obj diff --git a/pandas/io/sas/sas_xport.py b/pandas/io/sas/sas_xport.py index 52b25898fc67e..14e7ad9682db6 100644 --- a/pandas/io/sas/sas_xport.py +++ b/pandas/io/sas/sas_xport.py @@ -181,10 +181,6 @@ def _parse_float_vec(vec): # number sans exponent ieee1 = xport1 & 0x00ffffff - # Get the second half of the ibm number into the second half of - # the ieee number - ieee2 = xport2 - # The fraction bit to the left of the binary point in the ieee # format was set and the number was shifted 0, 1, 2, or 3 # places. This will tell us how to adjust the ibm exponent to be a 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/io/json/test_pandas.py b/pandas/tests/io/json/test_pandas.py index bcbac4400c953..d6e7c644cc780 100644 --- a/pandas/tests/io/json/test_pandas.py +++ b/pandas/tests/io/json/test_pandas.py @@ -642,6 +642,13 @@ def test_series_from_json_precise_float(self): result = read_json(s.to_json(), typ='series', precise_float=True) assert_series_equal(result, s, check_index_type=False) + def test_series_with_dtype(self): + # GH 21986 + s = Series([4.56, 4.56, 4.56]) + result = read_json(s.to_json(), typ='series', dtype=np.int64) + expected = Series([4] * 3) + assert_series_equal(result, expected) + def test_frame_from_json_precise_float(self): df = DataFrame([[4.56, 4.56, 4.56], [4.56, 4.56, 4.56]]) result = read_json(df.to_json(), precise_float=True)