Skip to content

CLN: Remove unused variables #21986

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jul 29, 2018
1 change: 0 additions & 1 deletion pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion pandas/core/arrays/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 2 additions & 0 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,7 @@ def rename(self, *args, **kwargs):
level = kwargs.pop('level', None)
axis = kwargs.pop('axis', None)
if axis is not None:
# TODO: axis is unused, is this just validating?
axis = self._get_axis_number(axis)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect the answer is yes, in which case, not assigning the variable is fine.


if kwargs:
Expand Down Expand Up @@ -5207,6 +5208,7 @@ def __copy__(self, deep=True):

def __deepcopy__(self, memo=None):
if memo is None:
# TODO: memo is unused
memo = {}
return self.copy(deep=True)

Expand Down
1 change: 0 additions & 1 deletion pandas/core/groupby/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,7 @@ def __copy__(self, **kwargs):
return self.copy(**kwargs)

def __deepcopy__(self, memo=None):
# TODO: memo is unused
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a standard signature, so maybe add a doc-string, you don't need to pass thru memo

if memo is None:
memo = {}
return self.copy(deep=True)
Expand Down
1 change: 1 addition & 0 deletions pandas/core/indexes/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 below?
cat = Categorical.from_codes(codes, categories=categories,
ordered=self.ordered)
return CategoricalIndex(cat, name=name)
Expand Down
1 change: 0 additions & 1 deletion pandas/core/indexes/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
4 changes: 1 addition & 3 deletions pandas/core/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -1255,6 +1255,7 @@ def take_nd(self, indexer, axis, new_mgr_locs=None, fill_tuple=None):
values = self.get_values()

if fill_tuple is None:
# TODO: fill_value is unused; should this be passed to take_nd?
fill_value = self.fill_value
new_values = algos.take_nd(values, indexer, axis=axis,
allow_fill=False)
Expand Down Expand Up @@ -2708,7 +2709,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
Expand Down Expand Up @@ -2881,11 +2881,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
Expand Down
2 changes: 0 additions & 2 deletions pandas/core/nanops.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

huh? is not used?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this not used?


# floating point error
#
Expand Down
6 changes: 4 additions & 2 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down Expand Up @@ -2479,6 +2478,7 @@ def sort_values(self, axis=0, ascending=True, inplace=False,
dtype: object
"""
inplace = validate_bool_kwarg(inplace, 'inplace')
# TODO: axis is unused, is this just validation?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are checked, so you don't need to assign

axis = self._get_axis_number(axis)

# GH 5856/5853
Expand Down Expand Up @@ -2651,6 +2651,7 @@ 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')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same with all of these

# TODO: axis is unused, is this just validation?
axis = self._get_axis_number(axis)
index = self.index

Expand Down Expand Up @@ -3072,6 +3073,7 @@ def _gotitem(self, key, ndim, subset=None):
versionadded='.. versionadded:: 0.20.0',
**_shared_doc_kwargs))
def aggregate(self, func, axis=0, *args, **kwargs):
# TODO: axis is unused, is this just validation?
axis = self._get_axis_number(axis)
result, how = self._aggregate(func, *args, **kwargs)
if result is None:
Expand Down Expand Up @@ -3918,7 +3920,7 @@ def dropna(self, axis=0, inplace=False, **kwargs):
if kwargs:
raise TypeError('dropna() got an unexpected keyword '
'argument "{0}"'.format(list(kwargs.keys())[0]))

# TODO: axis is unused, is this just validation?
axis = self._get_axis_number(axis or 0)

if self._can_hold_na:
Expand Down
1 change: 0 additions & 1 deletion pandas/core/sparse/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions pandas/core/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,7 @@ class _Rolling_and_Expanding(_Rolling):
def count(self):

blocks, obj, index = self._create_blocks()
# TODO: index & indexi, is this just validation?
index, indexi = self._get_index(index=index)

window = self._get_window()
Expand Down
2 changes: 2 additions & 0 deletions pandas/io/formats/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 block be elif? row_num here will
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is fine

# be overwritten.
row_num = len(frame)
if max_rows_adj == 1:
row_num = max_rows
Expand Down
1 change: 0 additions & 1 deletion pandas/io/formats/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ def _column_header():
return row

self.write('<thead>', indent)
row = []

indent += self.indent_delta

Expand Down
2 changes: 1 addition & 1 deletion pandas/io/formats/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def is_terminal():


def _get_terminal_size_windows():
res = None

try:
from ctypes import windll, create_string_buffer

Expand Down
1 change: 1 addition & 0 deletions pandas/io/json/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ def _get_object_parser(self, json):

if typ == 'series' or obj is None:
if not isinstance(dtype, bool):
# TODO: dtype is unused. Should this be an update on kwargs?
dtype = dict(data=dtype)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we can find an example that breaks because of this unused variable, that would be good for another PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, comment applies to many of the other variables in which you questioned whether it actually should be used, but previous authors didn't get around to implementing functionality with it.

obj = SeriesParser(json, **kwargs).parse()

Expand Down
1 change: 1 addition & 0 deletions pandas/io/sas/sas_xport.py
Original file line number Diff line number Diff line change
Expand Up @@ -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. Should it be used in the calc below?
ieee2 = xport2

# The fraction bit to the left of the binary point in the ieee
Expand Down
1 change: 0 additions & 1 deletion pandas/plotting/_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down