- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 19.2k
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
          
        
      | 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
          
        
      | 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
          
        
      | 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
          
        
      | 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
| 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
          
        
      | 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
| """ | ||
| # 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
          
        
      | 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. 
 | 
| 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
          
        
      | """ | ||
| 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 | 
| 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
| 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
| 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.