From 986abb3d3b080ef74e90d49bfad8ddefcbd60176 Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Tue, 12 Mar 2019 13:27:39 -0700 Subject: [PATCH 1/3] Fixed non-typing issues --- pandas/_libs/tslibs/nattype.pyx | 2 +- pandas/core/dtypes/dtypes.py | 2 +- pandas/io/formats/format.py | 1 - pandas/tests/frame/test_alter_axes.py | 5 +- pandas/tests/groupby/test_apply.py | 2 +- pandas/tests/groupby/test_grouping.py | 22 ++++----- .../indexes/interval/test_interval_tree.py | 2 +- pandas/tests/io/test_pytables.py | 4 +- pandas/tests/series/test_rank.py | 48 +++++++++---------- 9 files changed, 44 insertions(+), 44 deletions(-) diff --git a/pandas/_libs/tslibs/nattype.pyx b/pandas/_libs/tslibs/nattype.pyx index 79e2e256c501d..e71f7dfe8b8ce 100644 --- a/pandas/_libs/tslibs/nattype.pyx +++ b/pandas/_libs/tslibs/nattype.pyx @@ -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. diff --git a/pandas/core/dtypes/dtypes.py b/pandas/core/dtypes/dtypes.py index 11a132c4d14ee..b3d46b7dc76a6 100644 --- a/pandas/core/dtypes/dtypes.py +++ b/pandas/core/dtypes/dtypes.py @@ -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] ' diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index 91e5edc8de9f4..2bf0cd56daebf 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -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 diff --git a/pandas/tests/frame/test_alter_axes.py b/pandas/tests/frame/test_alter_axes.py index bc5cf30d096fd..ade77c8dadeda 100644 --- a/pandas/tests/frame/test_alter_axes.py +++ b/pandas/tests/frame/test_alter_axes.py @@ -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 @@ -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']) diff --git a/pandas/tests/groupby/test_apply.py b/pandas/tests/groupby/test_apply.py index 659d1a9cf9813..dea7e518ac605 100644 --- a/pandas/tests/groupby/test_apply.py +++ b/pandas/tests/groupby/test_apply.py @@ -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 diff --git a/pandas/tests/groupby/test_grouping.py b/pandas/tests/groupby/test_grouping.py index 44b5bd5f13992..bfb7f2636c8a0 100644 --- a/pandas/tests/groupby/test_grouping.py +++ b/pandas/tests/groupby/test_grouping.py @@ -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 diff --git a/pandas/tests/indexes/interval/test_interval_tree.py b/pandas/tests/indexes/interval/test_interval_tree.py index 5d9ef2a9a6c32..d924c0f1db38e 100644 --- a/pandas/tests/indexes/interval/test_interval_tree.py +++ b/pandas/tests/indexes/interval/test_interval_tree.py @@ -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', [ diff --git a/pandas/tests/io/test_pytables.py b/pandas/tests/io/test_pytables.py index 69ff32d1b728b..569a56b1ed526 100644 --- a/pandas/tests/io/test_pytables.py +++ b/pandas/tests/io/test_pytables.py @@ -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): diff --git a/pandas/tests/series/test_rank.py b/pandas/tests/series/test_rank.py index 373083c077e28..f92a5490ebcb5 100644 --- a/pandas/tests/series/test_rank.py +++ b/pandas/tests/series/test_rank.py @@ -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']) @@ -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']) @@ -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']) @@ -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']) @@ -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 From c7e35747d118dcfda0d196af0fee315caa0f9b19 Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Tue, 12 Mar 2019 13:35:17 -0700 Subject: [PATCH 2/3] Modified pep8speaks --- .pep8speaks.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.pep8speaks.yml b/.pep8speaks.yml index cbcb098c47125..51192f5cbb54f 100644 --- a/.pep8speaks.yml +++ b/.pep8speaks.yml @@ -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) From 2f2bffdcf8ac6c8e28a359530c5310366d2d492b Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Tue, 12 Mar 2019 13:36:50 -0700 Subject: [PATCH 3/3] Replaced tab with newline --- .pep8speaks.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pep8speaks.yml b/.pep8speaks.yml index 51192f5cbb54f..a03e6c6240db7 100644 --- a/.pep8speaks.yml +++ b/.pep8speaks.yml @@ -17,4 +17,4 @@ pycodestyle: - 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. - - F821 # undefined name (temporarily for type hints) + - F821 # undefined name (temporarily for type hints)