Skip to content
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

Merged
merged 10 commits into from
Jul 29, 2018
Merged

Conversation

mroeschke
Copy link
Member

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.

@@ -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.

@@ -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.

@@ -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)
Copy link
Member

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.

Copy link
Contributor

@jreback jreback left a 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

@@ -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

@@ -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
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?

@@ -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

@@ -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

@@ -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

@codecov
Copy link

codecov bot commented Jul 20, 2018

Codecov Report

Merging #21986 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Flag Coverage Δ
#multiple 90.47% <100%> (ø) ⬆️
#single 42.31% <25%> (ø) ⬆️
Impacted Files Coverage Δ
pandas/core/arrays/interval.py 92.33% <ø> (-0.03%) ⬇️
pandas/core/indexes/interval.py 94.11% <ø> (-0.02%) ⬇️
pandas/core/indexes/category.py 97.28% <ø> (ø) ⬆️
pandas/io/formats/terminal.py 21.25% <ø> (+0.26%) ⬆️
pandas/core/arrays/categorical.py 95.95% <ø> (-0.01%) ⬇️
pandas/plotting/_timeseries.py 65.28% <ø> (+0.33%) ⬆️
pandas/io/formats/html.py 88.81% <ø> (-0.04%) ⬇️
pandas/core/groupby/ops.py 96.57% <ø> (+0.21%) ⬆️
pandas/core/indexes/base.py 96.37% <ø> (ø) ⬆️
pandas/core/internals/blocks.py 94.45% <ø> (-0.02%) ⬇️
... and 8 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0b7a08b...05e4a36. Read the comment docs.

@@ -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)
Copy link
Member

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?

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 tested anywhere? I agree this should have broken things

Copy link
Member Author

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)

Copy link
Member Author

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

@@ -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
Copy link
Member

Choose a reason for hiding this comment

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

Validate typo

@jbrockmendel
Copy link
Member

Mostly looks good. There are a few places where missing arguments are added that may merit tests.

@jreback
Copy link
Contributor

jreback commented Jul 24, 2018

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)
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 tested anywhere? I agree this should have broken things

@jreback jreback added this to the 0.24.0 milestone Jul 25, 2018
@@ -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)
Copy link
Member Author

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.

Copy link
Contributor

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):
Copy link
Member Author

Choose a reason for hiding this comment

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

@mroeschke
Copy link
Member Author

I think everything should generally be covered with a test besides the take_nd modification explained above.

Copy link
Contributor

@jreback jreback left a 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.

@mroeschke
Copy link
Member Author

@jreback all green

@jreback jreback merged commit 0c58a82 into pandas-dev:master Jul 29, 2018
@jreback
Copy link
Contributor

jreback commented Jul 29, 2018

thanks @mroeschke

@mroeschke mroeschke deleted the remove_variables branch July 29, 2018 18:16
@mroeschke mroeschke mentioned this pull request Jul 29, 2018
1 task
Sup3rGeo pushed a commit to Sup3rGeo/pandas that referenced this pull request Oct 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants