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

Handle New PyFlakes Issues #25697

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .pep8speaks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ pycodestyle:
- E731, # do not assign a lambda expression, use a def
- C406, # Unnecessary list literal - rewrite as a dict literal.
- C408, # Unnecessary dict call - rewrite as a literal.
- C409 # Unnecessary list passed to tuple() - rewrite as a tuple literal.
- C409, # Unnecessary list passed to tuple() - rewrite as a tuple literal.
- F821 # undefined name (temporarily for type hints)
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not actually sure if we want to do this since it would affect all undefined names (not just types) but I couldn't find a way to disambiguate save updating all of the type comments to have an ignore directive. If we wanted to go that route would probably be easier to move forward with some pieces of #25622 but open to thoughts

Copy link
Contributor

Choose a reason for hiding this comment

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

That's unfortunate. I think it's probably better to pin to an older flake8 until #25622 is sorted out.

Copy link
Contributor

@h-vetinari h-vetinari Mar 13, 2019

Choose a reason for hiding this comment

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

FWIW, the other changes in this PR seem worthwhile to me, irrespective of what happens with MyPy/F821.

Copy link
Member

Choose a reason for hiding this comment

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

F821 is a doozy, is one of the checks that frequently catches actual bugs. I’d very much prefer not to ignore it.

Copy link
Member Author

Choose a reason for hiding this comment

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

@jbrockmendel for sure. The solution here is tucked away in #25622 so I'll be splitting that out when the timing is right. Waiting for official drop of Py2 in CI before that can happen

2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/nattype.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ class NaTType(_NaT):

.. versionadded:: 0.23.0
""")
day_name = _make_nan_func('day_name', # noqa:E128
day_name = _make_nan_func('day_name', # noqa:E128
"""
Return the day name of the Timestamp with specified locale.

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/dtypes/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ def construct_from_string(cls, string):

if (string.lower() == 'interval' or
cls._match.search(string) is not None):
return cls(string)
return cls(string)

msg = ('Incorrectly formatted string passed to constructor. '
'Valid formats include Interval or Interval[dtype] '
Expand Down
1 change: 0 additions & 1 deletion pandas/io/formats/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,6 @@ def _chk_truncate(self):
max_rows = self.max_rows

if max_cols == 0 or max_rows == 0: # assume we are in the terminal
# (why else = 0)
(w, h) = get_terminal_size()
self.w = w
self.h = h
Expand Down
5 changes: 3 additions & 2 deletions pandas/tests/frame/test_alter_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ def test_set_index_pass_arrays_duplicate(self, frame_of_index_cols, drop,
# need to adapt first drop for case that both keys are 'A' --
# cannot drop the same column twice;
# use "is" because == would give ambiguous Boolean error for containers
first_drop = False if (keys[0] is 'A' and keys[1] is 'A') else drop
first_drop = False if (
keys[0] is 'A' and keys[1] is 'A') else drop # noqa: F632

# to test against already-tested behaviour, we add sequentially,
# hence second append always True; must wrap keys in list, otherwise
Expand Down Expand Up @@ -1272,7 +1273,7 @@ def test_rename_axis_style_raises(self):
df.rename(id, mapper=id)

def test_reindex_api_equivalence(self):
# equivalence of the labels/axis and index/columns API's
# equivalence of the labels/axis and index/columns API's
df = DataFrame([[1, 2, 3], [3, 4, 5], [5, 6, 7]],
index=['a', 'b', 'c'],
columns=['d', 'e', 'f'])
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/groupby/test_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


def test_apply_issues():
# GH 5788
# GH 5788

s = """2011.05.16,00:00,1.40893
2011.05.16,01:00,1.40760
Expand Down
22 changes: 11 additions & 11 deletions pandas/tests/groupby/test_grouping.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,17 +649,17 @@ def test_groupby_with_single_column(self):
tm.assert_frame_equal(df.groupby('a').nth(1), exp)

def test_gb_key_len_equal_axis_len(self):
# GH16843
# test ensures that index and column keys are recognized correctly
# when number of keys equals axis length of groupby
df = pd.DataFrame([['foo', 'bar', 'B', 1],
['foo', 'bar', 'B', 2],
['foo', 'baz', 'C', 3]],
columns=['first', 'second', 'third', 'one'])
df = df.set_index(['first', 'second'])
df = df.groupby(['first', 'second', 'third']).size()
assert df.loc[('foo', 'bar', 'B')] == 2
assert df.loc[('foo', 'baz', 'C')] == 1
# GH16843
# test ensures that index and column keys are recognized correctly
# when number of keys equals axis length of groupby
df = pd.DataFrame([['foo', 'bar', 'B', 1],
['foo', 'bar', 'B', 2],
['foo', 'baz', 'C', 3]],
columns=['first', 'second', 'third', 'one'])
df = df.set_index(['first', 'second'])
df = df.groupby(['first', 'second', 'third']).size()
assert df.loc[('foo', 'bar', 'B')] == 2
assert df.loc[('foo', 'baz', 'C')] == 1


# groups & iteration
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexes/interval/test_interval_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def test_is_overlapping_endpoints(self, closed, order):
left, right = np.arange(3), np.arange(1, 4)
tree = IntervalTree(left[order], right[order], closed=closed)
result = tree.is_overlapping
expected = closed is 'both'
expected = closed == 'both'
assert result is expected

@pytest.mark.parametrize('left, right', [
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/io/test_pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -2386,8 +2386,8 @@ def test_empty_series_frame(self):
@pytest.mark.parametrize(
'dtype', [np.int64, np.float64, np.object, 'm8[ns]', 'M8[ns]'])
def test_empty_series(self, dtype):
s = Series(dtype=dtype)
self._check_roundtrip(s, tm.assert_series_equal)
s = Series(dtype=dtype)
self._check_roundtrip(s, tm.assert_series_equal)

def test_can_serialize_dates(self):

Expand Down
48 changes: 24 additions & 24 deletions pandas/tests/series/test_rank.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,10 +421,10 @@ def test_rank_modify_inplace(self):
([1, 1, 3, 3, 5, 5], [1. / 3, 1. / 3, 2. / 3, 2. / 3, 3. / 3, 3. / 3]),
([-5, -4, -3, -2, -1], [1. / 5, 2. / 5, 3. / 5, 4. / 5, 5. / 5])])
def test_rank_dense_pct(dtype, ser, exp):
s = Series(ser).astype(dtype)
result = s.rank(method='dense', pct=True)
expected = Series(exp).astype(result.dtype)
assert_series_equal(result, expected)
s = Series(ser).astype(dtype)
result = s.rank(method='dense', pct=True)
expected = Series(exp).astype(result.dtype)
assert_series_equal(result, expected)


@pytest.mark.parametrize('dtype', ['O', 'f8', 'i8'])
Expand All @@ -439,10 +439,10 @@ def test_rank_dense_pct(dtype, ser, exp):
([1, 1, 3, 3, 5, 5], [1. / 6, 1. / 6, 3. / 6, 3. / 6, 5. / 6, 5. / 6]),
([-5, -4, -3, -2, -1], [1. / 5, 2. / 5, 3. / 5, 4. / 5, 5. / 5])])
def test_rank_min_pct(dtype, ser, exp):
s = Series(ser).astype(dtype)
result = s.rank(method='min', pct=True)
expected = Series(exp).astype(result.dtype)
assert_series_equal(result, expected)
s = Series(ser).astype(dtype)
result = s.rank(method='min', pct=True)
expected = Series(exp).astype(result.dtype)
assert_series_equal(result, expected)


@pytest.mark.parametrize('dtype', ['O', 'f8', 'i8'])
Expand All @@ -457,10 +457,10 @@ def test_rank_min_pct(dtype, ser, exp):
([1, 1, 3, 3, 5, 5], [2. / 6, 2. / 6, 4. / 6, 4. / 6, 6. / 6, 6. / 6]),
([-5, -4, -3, -2, -1], [1. / 5, 2. / 5, 3. / 5, 4. / 5, 5. / 5])])
def test_rank_max_pct(dtype, ser, exp):
s = Series(ser).astype(dtype)
result = s.rank(method='max', pct=True)
expected = Series(exp).astype(result.dtype)
assert_series_equal(result, expected)
s = Series(ser).astype(dtype)
result = s.rank(method='max', pct=True)
expected = Series(exp).astype(result.dtype)
assert_series_equal(result, expected)


@pytest.mark.parametrize('dtype', ['O', 'f8', 'i8'])
Expand All @@ -476,10 +476,10 @@ def test_rank_max_pct(dtype, ser, exp):
[1.5 / 6, 1.5 / 6, 3.5 / 6, 3.5 / 6, 5.5 / 6, 5.5 / 6]),
([-5, -4, -3, -2, -1], [1. / 5, 2. / 5, 3. / 5, 4. / 5, 5. / 5])])
def test_rank_average_pct(dtype, ser, exp):
s = Series(ser).astype(dtype)
result = s.rank(method='average', pct=True)
expected = Series(exp).astype(result.dtype)
assert_series_equal(result, expected)
s = Series(ser).astype(dtype)
result = s.rank(method='average', pct=True)
expected = Series(exp).astype(result.dtype)
assert_series_equal(result, expected)


@pytest.mark.parametrize('dtype', ['f8', 'i8'])
Expand All @@ -494,16 +494,16 @@ def test_rank_average_pct(dtype, ser, exp):
([1, 1, 3, 3, 5, 5], [1. / 6, 2. / 6, 3. / 6, 4. / 6, 5. / 6, 6. / 6]),
([-5, -4, -3, -2, -1], [1. / 5, 2. / 5, 3. / 5, 4. / 5, 5. / 5])])
def test_rank_first_pct(dtype, ser, exp):
s = Series(ser).astype(dtype)
result = s.rank(method='first', pct=True)
expected = Series(exp).astype(result.dtype)
assert_series_equal(result, expected)
s = Series(ser).astype(dtype)
result = s.rank(method='first', pct=True)
expected = Series(exp).astype(result.dtype)
assert_series_equal(result, expected)


@pytest.mark.single
@pytest.mark.high_memory
def test_pct_max_many_rows():
# GH 18271
s = Series(np.arange(2**24 + 1))
result = s.rank(pct=True).max()
assert result == 1
# GH 18271
s = Series(np.arange(2**24 + 1))
result = s.rank(pct=True).max()
assert result == 1