-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
CLN: Remove unused variables #21986
Conversation
pandas/core/generic.py
Outdated
@@ -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) |
There was a problem hiding this comment.
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.
pandas/io/json/json.py
Outdated
@@ -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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
pandas/core/nanops.py
Outdated
@@ -479,6 +479,9 @@ def nanvar(values, axis=None, skipna=True, ddof=1): | |||
|
|||
@disallow('M8', 'm8') | |||
def nansem(values, axis=None, skipna=True, ddof=1): | |||
# This checks if non-numeric-like data is passed with numeric_only=False | |||
# and raises a TypeError otherwise | |||
var = nanvar(values, axis, skipna, ddof=ddof) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If var
isn't used, don't assign the result of nanvar
to a variable. Just call it without.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rather than comments I would just like to see if changing breaks things. it might be that we are not testing that case or its unused code
pandas/core/indexes/base.py
Outdated
@@ -979,6 +979,7 @@ def __copy__(self, **kwargs): | |||
return self.copy(**kwargs) | |||
|
|||
def __deepcopy__(self, memo=None): | |||
# TODO: memo is unused |
There was a problem hiding this comment.
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
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
huh? is not used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this not used?
pandas/core/series.py
Outdated
@@ -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? |
There was a problem hiding this comment.
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
@@ -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') |
There was a problem hiding this comment.
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
pandas/io/formats/format.py
Outdated
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is fine
Codecov Report
@@ Coverage Diff @@
## master #21986 +/- ##
==========================================
+ Coverage 92.06% 92.06% +<.01%
==========================================
Files 170 170
Lines 50705 50689 -16
==========================================
- Hits 46680 46668 -12
+ Misses 4025 4021 -4
Continue to review full report at Codecov.
|
@@ -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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We’re there cases before where the wrong thing was passed? I.e. None != ordered != self.ordered?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this tested anywhere? I agree this should have broken things
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It appears that all instances of this private method _create_from_codes
in the codebase never passed an arg to ordered
(i.e. ordered
always defaulted to None
which always got reassigned to self.ordered
here)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(pandas-dev) matthewroeschke:pandas-mroeschke matthewroeschke$ grep -R --include="*.py" _create_from_codes .
./pandas/core/indexes/category.py: def _create_from_codes(self, codes, categories=None, ordered=None,
./pandas/core/indexes/category.py: new_target = self._create_from_codes(codes)
./pandas/core/indexes/category.py: return self._create_from_codes(taken)
./pandas/core/indexes/category.py: return self._create_from_codes(np.delete(self.codes, loc))
./pandas/core/indexes/category.py: return self._create_from_codes(codes)
./pandas/core/indexes/category.py: result = self._create_from_codes(codes, name=name)
./pandas/core/indexes/category.py: # if name is None, _create_from_codes sets self.name
pandas/core/series.py
Outdated
@@ -2479,7 +2478,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) | |||
# Valida the axis parameter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Validate typo
Mostly looks good. There are a few places where missing arguments are added that may merit tests. |
can you rebase |
@@ -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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this tested anywhere? I agree this should have broken things
@@ -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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This modification is deep within the internals (block's definition of take_nd
), and I am not sure how to really add a test for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this actually isn't used since allow_fill=False
@@ -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): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test should hit the modification made here: https://github.com/mroeschke/pandas/blob/0d7f07783ad9a42bb3fc7f0e3dda0c01b877fe57/pandas/io/json/json.py#L550
I think everything should generally be covered with a test besides the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor questions, rebase and ping on green.
@jreback all green |
thanks @mroeschke |
Breaking up #21974.
Removes non-noqa, seemingly non-controversial, unused local variables according to PyCharm. These are mostly redefined elsewhere or not used.
I added some TODO comments about other unused local variables that seem misused.