diff --git a/doc/source/user_guide/io.rst b/doc/source/user_guide/io.rst index e2f8ac09d8873..8c8469b93db68 100644 --- a/doc/source/user_guide/io.rst +++ b/doc/source/user_guide/io.rst @@ -3023,6 +3023,7 @@ Read in the content of the "books.xml" as instance of ``StringIO`` or Even read XML from AWS S3 buckets such as Python Software Foundation's IRS 990 Form: .. ipython:: python + :okwarning: df = pd.read_xml( "s3://irs-form-990/201923199349319487_public.xml", diff --git a/pandas/api/__init__.py b/pandas/api/__init__.py index c22f37f2ef292..80202b3569862 100644 --- a/pandas/api/__init__.py +++ b/pandas/api/__init__.py @@ -1,5 +1,5 @@ """ public toolkit API """ -from pandas.api import ( # noqa +from pandas.api import ( # noqa:F401 extensions, indexers, types, diff --git a/pandas/core/algorithms.py b/pandas/core/algorithms.py index acc66ae9deca7..763e76f8497fa 100644 --- a/pandas/core/algorithms.py +++ b/pandas/core/algorithms.py @@ -1849,5 +1849,5 @@ def union_with_duplicates(lvals: ArrayLike, rvals: ArrayLike) -> ArrayLike: unique_array = ensure_wrapped_if_datetimelike(unique_array) for i, value in enumerate(unique_array): - indexer += [i] * int(max(l_count[value], r_count[value])) + indexer += [i] * int(max(l_count.at[value], r_count.at[value])) return unique_array.take(indexer) diff --git a/pandas/core/arrays/floating.py b/pandas/core/arrays/floating.py index 6d6cc03a1c83e..9be2201c566a4 100644 --- a/pandas/core/arrays/floating.py +++ b/pandas/core/arrays/floating.py @@ -176,9 +176,7 @@ def coerce_to_array( if mask.any(): values = values.copy() values[mask] = np.nan - values = values.astype(dtype, copy=False) # , casting="safe") - else: - values = values.astype(dtype, copy=False) # , casting="safe") + values = values.astype(dtype, copy=False) # , casting="safe") return values, mask diff --git a/pandas/core/arrays/integer.py b/pandas/core/arrays/integer.py index d8b7bf2b86d2c..d01068a0d408c 100644 --- a/pandas/core/arrays/integer.py +++ b/pandas/core/arrays/integer.py @@ -214,9 +214,9 @@ def coerce_to_array( else: assert len(mask) == len(values) - if not values.ndim == 1: + if values.ndim != 1: raise TypeError("values must be a 1D list-like") - if not mask.ndim == 1: + if mask.ndim != 1: raise TypeError("mask must be a 1D list-like") # infer dtype if needed diff --git a/pandas/core/dtypes/missing.py b/pandas/core/dtypes/missing.py index eea3fa37b7435..c189134237554 100644 --- a/pandas/core/dtypes/missing.py +++ b/pandas/core/dtypes/missing.py @@ -162,7 +162,6 @@ def _isna(obj, inf_as_na: bool = False): return libmissing.checknull_old(obj) else: return libmissing.checknull(obj) - # hack (for now) because MI registers as ndarray elif isinstance(obj, ABCMultiIndex): raise NotImplementedError("isna is not defined for MultiIndex") elif isinstance(obj, type): diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index 7b6a76f0a5d10..ca81d54a0fb86 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -309,7 +309,7 @@ def _slice(self, slicer) -> ArrayLike: return self.values[slicer] @final - def getitem_block(self, slicer) -> Block: + def getitem_block(self, slicer: slice | npt.NDArray[np.intp]) -> Block: """ Perform __getitem__-like, return result as block. @@ -326,7 +326,9 @@ def getitem_block(self, slicer) -> Block: return type(self)(new_values, new_mgr_locs, self.ndim) @final - def getitem_block_columns(self, slicer, new_mgr_locs: BlockPlacement) -> Block: + def getitem_block_columns( + self, slicer: slice, new_mgr_locs: BlockPlacement + ) -> Block: """ Perform __getitem__-like, return result as block. diff --git a/pandas/core/reshape/tile.py b/pandas/core/reshape/tile.py index a1b058224795e..8cf94e5e433a6 100644 --- a/pandas/core/reshape/tile.py +++ b/pandas/core/reshape/tile.py @@ -443,7 +443,8 @@ def _bins_to_cuts( ) elif ordered and len(set(labels)) != len(labels): raise ValueError( - "labels must be unique if ordered=True; pass ordered=False for duplicate labels" # noqa + "labels must be unique if ordered=True; pass ordered=False " + "for duplicate labels" ) else: if len(labels) != len(bins) - 1: diff --git a/pandas/io/sas/__init__.py b/pandas/io/sas/__init__.py index 8f81352e6aecb..71027fd064f3d 100644 --- a/pandas/io/sas/__init__.py +++ b/pandas/io/sas/__init__.py @@ -1 +1 @@ -from pandas.io.sas.sasreader import read_sas # noqa +from pandas.io.sas.sasreader import read_sas # noqa:F401 diff --git a/pandas/tests/arrays/boolean/test_function.py b/pandas/tests/arrays/boolean/test_function.py index d90655b6e2820..2f1a3121cdf5b 100644 --- a/pandas/tests/arrays/boolean/test_function.py +++ b/pandas/tests/arrays/boolean/test_function.py @@ -59,8 +59,8 @@ def test_ufuncs_unary(ufunc): expected[a._mask] = np.nan tm.assert_extension_array_equal(result, expected) - s = pd.Series(a) - result = ufunc(s) + ser = pd.Series(a) + result = ufunc(ser) expected = pd.Series(ufunc(a._data), dtype="boolean") expected[a._mask] = np.nan tm.assert_series_equal(result, expected) @@ -86,8 +86,8 @@ def test_value_counts_na(): def test_value_counts_with_normalize(): - s = pd.Series([True, False, pd.NA], dtype="boolean") - result = s.value_counts(normalize=True) + ser = pd.Series([True, False, pd.NA], dtype="boolean") + result = ser.value_counts(normalize=True) expected = pd.Series([1, 1], index=[True, False], dtype="Float64") / 2 tm.assert_series_equal(result, expected) @@ -102,7 +102,7 @@ def test_diff(): ) tm.assert_extension_array_equal(result, expected) - s = pd.Series(a) - result = s.diff() + ser = pd.Series(a) + result = ser.diff() expected = pd.Series(expected) tm.assert_series_equal(result, expected) diff --git a/pandas/tests/arrays/categorical/test_constructors.py b/pandas/tests/arrays/categorical/test_constructors.py index ee24ecb4964ec..50ecbb9eb705a 100644 --- a/pandas/tests/arrays/categorical/test_constructors.py +++ b/pandas/tests/arrays/categorical/test_constructors.py @@ -248,9 +248,7 @@ def test_constructor(self): # this is a legitimate constructor with tm.assert_produces_warning(None): - c = Categorical( # noqa - np.array([], dtype="int64"), categories=[3, 2, 1], ordered=True - ) + Categorical(np.array([], dtype="int64"), categories=[3, 2, 1], ordered=True) def test_constructor_with_existing_categories(self): # GH25318: constructing with pd.Series used to bogusly skip recoding diff --git a/pandas/tests/arrays/categorical/test_repr.py b/pandas/tests/arrays/categorical/test_repr.py index e23fbb16190ea..678109b2c2497 100644 --- a/pandas/tests/arrays/categorical/test_repr.py +++ b/pandas/tests/arrays/categorical/test_repr.py @@ -77,7 +77,7 @@ def test_unicode_print(self): expected = """\ ['ああああ', 'いいいいい', 'ううううううう', 'ああああ', 'いいいいい', ..., 'いいいいい', 'ううううううう', 'ああああ', 'いいいいい', 'ううううううう'] Length: 60 -Categories (3, object): ['ああああ', 'いいいいい', 'ううううううう']""" # noqa +Categories (3, object): ['ああああ', 'いいいいい', 'ううううううう']""" # noqa:E501 assert repr(c) == expected @@ -88,7 +88,7 @@ def test_unicode_print(self): c = Categorical(["ああああ", "いいいいい", "ううううううう"] * 20) expected = """['ああああ', 'いいいいい', 'ううううううう', 'ああああ', 'いいいいい', ..., 'いいいいい', 'ううううううう', 'ああああ', 'いいいいい', 'ううううううう'] Length: 60 -Categories (3, object): ['ああああ', 'いいいいい', 'ううううううう']""" # noqa +Categories (3, object): ['ああああ', 'いいいいい', 'ううううううう']""" # noqa:E501 assert repr(c) == expected @@ -213,14 +213,14 @@ def test_categorical_repr_datetime_ordered(self): c = Categorical(idx, ordered=True) exp = """[2011-01-01 09:00:00, 2011-01-01 10:00:00, 2011-01-01 11:00:00, 2011-01-01 12:00:00, 2011-01-01 13:00:00] Categories (5, datetime64[ns]): [2011-01-01 09:00:00 < 2011-01-01 10:00:00 < 2011-01-01 11:00:00 < - 2011-01-01 12:00:00 < 2011-01-01 13:00:00]""" # noqa + 2011-01-01 12:00:00 < 2011-01-01 13:00:00]""" # noqa:E501 assert repr(c) == exp c = Categorical(idx.append(idx), categories=idx, ordered=True) exp = """[2011-01-01 09:00:00, 2011-01-01 10:00:00, 2011-01-01 11:00:00, 2011-01-01 12:00:00, 2011-01-01 13:00:00, 2011-01-01 09:00:00, 2011-01-01 10:00:00, 2011-01-01 11:00:00, 2011-01-01 12:00:00, 2011-01-01 13:00:00] Categories (5, datetime64[ns]): [2011-01-01 09:00:00 < 2011-01-01 10:00:00 < 2011-01-01 11:00:00 < - 2011-01-01 12:00:00 < 2011-01-01 13:00:00]""" # noqa + 2011-01-01 12:00:00 < 2011-01-01 13:00:00]""" # noqa:E501 assert repr(c) == exp @@ -229,7 +229,7 @@ def test_categorical_repr_datetime_ordered(self): exp = """[2011-01-01 09:00:00-05:00, 2011-01-01 10:00:00-05:00, 2011-01-01 11:00:00-05:00, 2011-01-01 12:00:00-05:00, 2011-01-01 13:00:00-05:00] Categories (5, datetime64[ns, US/Eastern]): [2011-01-01 09:00:00-05:00 < 2011-01-01 10:00:00-05:00 < 2011-01-01 11:00:00-05:00 < 2011-01-01 12:00:00-05:00 < - 2011-01-01 13:00:00-05:00]""" # noqa + 2011-01-01 13:00:00-05:00]""" # noqa:E501 assert repr(c) == exp @@ -237,7 +237,7 @@ def test_categorical_repr_datetime_ordered(self): exp = """[2011-01-01 09:00:00-05:00, 2011-01-01 10:00:00-05:00, 2011-01-01 11:00:00-05:00, 2011-01-01 12:00:00-05:00, 2011-01-01 13:00:00-05:00, 2011-01-01 09:00:00-05:00, 2011-01-01 10:00:00-05:00, 2011-01-01 11:00:00-05:00, 2011-01-01 12:00:00-05:00, 2011-01-01 13:00:00-05:00] Categories (5, datetime64[ns, US/Eastern]): [2011-01-01 09:00:00-05:00 < 2011-01-01 10:00:00-05:00 < 2011-01-01 11:00:00-05:00 < 2011-01-01 12:00:00-05:00 < - 2011-01-01 13:00:00-05:00]""" # noqa + 2011-01-01 13:00:00-05:00]""" # noqa:E501 assert repr(c) == exp @@ -257,14 +257,14 @@ def test_categorical_repr_period(self): c = Categorical(idx) exp = """[2011-01-01 09:00, 2011-01-01 10:00, 2011-01-01 11:00, 2011-01-01 12:00, 2011-01-01 13:00] Categories (5, period[H]): [2011-01-01 09:00, 2011-01-01 10:00, 2011-01-01 11:00, 2011-01-01 12:00, - 2011-01-01 13:00]""" # noqa + 2011-01-01 13:00]""" # noqa:E501 assert repr(c) == exp c = Categorical(idx.append(idx), categories=idx) exp = """[2011-01-01 09:00, 2011-01-01 10:00, 2011-01-01 11:00, 2011-01-01 12:00, 2011-01-01 13:00, 2011-01-01 09:00, 2011-01-01 10:00, 2011-01-01 11:00, 2011-01-01 12:00, 2011-01-01 13:00] Categories (5, period[H]): [2011-01-01 09:00, 2011-01-01 10:00, 2011-01-01 11:00, 2011-01-01 12:00, - 2011-01-01 13:00]""" # noqa + 2011-01-01 13:00]""" # noqa:E501 assert repr(c) == exp @@ -277,7 +277,7 @@ def test_categorical_repr_period(self): c = Categorical(idx.append(idx), categories=idx) exp = """[2011-01, 2011-02, 2011-03, 2011-04, 2011-05, 2011-01, 2011-02, 2011-03, 2011-04, 2011-05] -Categories (5, period[M]): [2011-01, 2011-02, 2011-03, 2011-04, 2011-05]""" # noqa +Categories (5, period[M]): [2011-01, 2011-02, 2011-03, 2011-04, 2011-05]""" # noqa:E501 assert repr(c) == exp @@ -286,14 +286,14 @@ def test_categorical_repr_period_ordered(self): c = Categorical(idx, ordered=True) exp = """[2011-01-01 09:00, 2011-01-01 10:00, 2011-01-01 11:00, 2011-01-01 12:00, 2011-01-01 13:00] Categories (5, period[H]): [2011-01-01 09:00 < 2011-01-01 10:00 < 2011-01-01 11:00 < 2011-01-01 12:00 < - 2011-01-01 13:00]""" # noqa + 2011-01-01 13:00]""" # noqa:E501 assert repr(c) == exp c = Categorical(idx.append(idx), categories=idx, ordered=True) exp = """[2011-01-01 09:00, 2011-01-01 10:00, 2011-01-01 11:00, 2011-01-01 12:00, 2011-01-01 13:00, 2011-01-01 09:00, 2011-01-01 10:00, 2011-01-01 11:00, 2011-01-01 12:00, 2011-01-01 13:00] Categories (5, period[H]): [2011-01-01 09:00 < 2011-01-01 10:00 < 2011-01-01 11:00 < 2011-01-01 12:00 < - 2011-01-01 13:00]""" # noqa + 2011-01-01 13:00]""" # noqa:E501 assert repr(c) == exp @@ -306,7 +306,7 @@ def test_categorical_repr_period_ordered(self): c = Categorical(idx.append(idx), categories=idx, ordered=True) exp = """[2011-01, 2011-02, 2011-03, 2011-04, 2011-05, 2011-01, 2011-02, 2011-03, 2011-04, 2011-05] -Categories (5, period[M]): [2011-01 < 2011-02 < 2011-03 < 2011-04 < 2011-05]""" # noqa +Categories (5, period[M]): [2011-01 < 2011-02 < 2011-03 < 2011-04 < 2011-05]""" # noqa:E501 assert repr(c) == exp @@ -330,7 +330,7 @@ def test_categorical_repr_timedelta(self): Length: 20 Categories (20, timedelta64[ns]): [0 days 01:00:00, 1 days 01:00:00, 2 days 01:00:00, 3 days 01:00:00, ..., 16 days 01:00:00, 17 days 01:00:00, - 18 days 01:00:00, 19 days 01:00:00]""" # noqa + 18 days 01:00:00, 19 days 01:00:00]""" # noqa:E501 assert repr(c) == exp @@ -339,7 +339,7 @@ def test_categorical_repr_timedelta(self): Length: 40 Categories (20, timedelta64[ns]): [0 days 01:00:00, 1 days 01:00:00, 2 days 01:00:00, 3 days 01:00:00, ..., 16 days 01:00:00, 17 days 01:00:00, - 18 days 01:00:00, 19 days 01:00:00]""" # noqa + 18 days 01:00:00, 19 days 01:00:00]""" # noqa:E501 assert repr(c) == exp @@ -363,7 +363,7 @@ def test_categorical_repr_timedelta_ordered(self): Length: 20 Categories (20, timedelta64[ns]): [0 days 01:00:00 < 1 days 01:00:00 < 2 days 01:00:00 < 3 days 01:00:00 ... 16 days 01:00:00 < 17 days 01:00:00 < - 18 days 01:00:00 < 19 days 01:00:00]""" # noqa + 18 days 01:00:00 < 19 days 01:00:00]""" # noqa:E501 assert repr(c) == exp @@ -372,26 +372,26 @@ def test_categorical_repr_timedelta_ordered(self): Length: 40 Categories (20, timedelta64[ns]): [0 days 01:00:00 < 1 days 01:00:00 < 2 days 01:00:00 < 3 days 01:00:00 ... 16 days 01:00:00 < 17 days 01:00:00 < - 18 days 01:00:00 < 19 days 01:00:00]""" # noqa + 18 days 01:00:00 < 19 days 01:00:00]""" # noqa:E501 assert repr(c) == exp def test_categorical_index_repr(self): idx = CategoricalIndex(Categorical([1, 2, 3])) - exp = """CategoricalIndex([1, 2, 3], categories=[1, 2, 3], ordered=False, dtype='category')""" # noqa + exp = """CategoricalIndex([1, 2, 3], categories=[1, 2, 3], ordered=False, dtype='category')""" # noqa:E501 assert repr(idx) == exp i = CategoricalIndex(Categorical(np.arange(10))) - exp = """CategoricalIndex([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], categories=[0, 1, 2, 3, 4, 5, 6, 7, ...], ordered=False, dtype='category')""" # noqa + exp = """CategoricalIndex([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], categories=[0, 1, 2, 3, 4, 5, 6, 7, ...], ordered=False, dtype='category')""" # noqa:E501 assert repr(i) == exp def test_categorical_index_repr_ordered(self): i = CategoricalIndex(Categorical([1, 2, 3], ordered=True)) - exp = """CategoricalIndex([1, 2, 3], categories=[1, 2, 3], ordered=True, dtype='category')""" # noqa + exp = """CategoricalIndex([1, 2, 3], categories=[1, 2, 3], ordered=True, dtype='category')""" # noqa:E501 assert repr(i) == exp i = CategoricalIndex(Categorical(np.arange(10), ordered=True)) - exp = """CategoricalIndex([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], categories=[0, 1, 2, 3, 4, 5, 6, 7, ...], ordered=True, dtype='category')""" # noqa + exp = """CategoricalIndex([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], categories=[0, 1, 2, 3, 4, 5, 6, 7, ...], ordered=True, dtype='category')""" # noqa:E501 assert repr(i) == exp def test_categorical_index_repr_datetime(self): @@ -400,7 +400,7 @@ def test_categorical_index_repr_datetime(self): exp = """CategoricalIndex(['2011-01-01 09:00:00', '2011-01-01 10:00:00', '2011-01-01 11:00:00', '2011-01-01 12:00:00', '2011-01-01 13:00:00'], - categories=[2011-01-01 09:00:00, 2011-01-01 10:00:00, 2011-01-01 11:00:00, 2011-01-01 12:00:00, 2011-01-01 13:00:00], ordered=False, dtype='category')""" # noqa + categories=[2011-01-01 09:00:00, 2011-01-01 10:00:00, 2011-01-01 11:00:00, 2011-01-01 12:00:00, 2011-01-01 13:00:00], ordered=False, dtype='category')""" # noqa:E501 assert repr(i) == exp @@ -409,7 +409,7 @@ def test_categorical_index_repr_datetime(self): exp = """CategoricalIndex(['2011-01-01 09:00:00-05:00', '2011-01-01 10:00:00-05:00', '2011-01-01 11:00:00-05:00', '2011-01-01 12:00:00-05:00', '2011-01-01 13:00:00-05:00'], - categories=[2011-01-01 09:00:00-05:00, 2011-01-01 10:00:00-05:00, 2011-01-01 11:00:00-05:00, 2011-01-01 12:00:00-05:00, 2011-01-01 13:00:00-05:00], ordered=False, dtype='category')""" # noqa + categories=[2011-01-01 09:00:00-05:00, 2011-01-01 10:00:00-05:00, 2011-01-01 11:00:00-05:00, 2011-01-01 12:00:00-05:00, 2011-01-01 13:00:00-05:00], ordered=False, dtype='category')""" # noqa:E501 assert repr(i) == exp @@ -419,7 +419,7 @@ def test_categorical_index_repr_datetime_ordered(self): exp = """CategoricalIndex(['2011-01-01 09:00:00', '2011-01-01 10:00:00', '2011-01-01 11:00:00', '2011-01-01 12:00:00', '2011-01-01 13:00:00'], - categories=[2011-01-01 09:00:00, 2011-01-01 10:00:00, 2011-01-01 11:00:00, 2011-01-01 12:00:00, 2011-01-01 13:00:00], ordered=True, dtype='category')""" # noqa + categories=[2011-01-01 09:00:00, 2011-01-01 10:00:00, 2011-01-01 11:00:00, 2011-01-01 12:00:00, 2011-01-01 13:00:00], ordered=True, dtype='category')""" # noqa:E501 assert repr(i) == exp @@ -428,7 +428,7 @@ def test_categorical_index_repr_datetime_ordered(self): exp = """CategoricalIndex(['2011-01-01 09:00:00-05:00', '2011-01-01 10:00:00-05:00', '2011-01-01 11:00:00-05:00', '2011-01-01 12:00:00-05:00', '2011-01-01 13:00:00-05:00'], - categories=[2011-01-01 09:00:00-05:00, 2011-01-01 10:00:00-05:00, 2011-01-01 11:00:00-05:00, 2011-01-01 12:00:00-05:00, 2011-01-01 13:00:00-05:00], ordered=True, dtype='category')""" # noqa + categories=[2011-01-01 09:00:00-05:00, 2011-01-01 10:00:00-05:00, 2011-01-01 11:00:00-05:00, 2011-01-01 12:00:00-05:00, 2011-01-01 13:00:00-05:00], ordered=True, dtype='category')""" # noqa:E501 assert repr(i) == exp @@ -438,7 +438,7 @@ def test_categorical_index_repr_datetime_ordered(self): '2011-01-01 13:00:00-05:00', '2011-01-01 09:00:00-05:00', '2011-01-01 10:00:00-05:00', '2011-01-01 11:00:00-05:00', '2011-01-01 12:00:00-05:00', '2011-01-01 13:00:00-05:00'], - categories=[2011-01-01 09:00:00-05:00, 2011-01-01 10:00:00-05:00, 2011-01-01 11:00:00-05:00, 2011-01-01 12:00:00-05:00, 2011-01-01 13:00:00-05:00], ordered=True, dtype='category')""" # noqa + categories=[2011-01-01 09:00:00-05:00, 2011-01-01 10:00:00-05:00, 2011-01-01 11:00:00-05:00, 2011-01-01 12:00:00-05:00, 2011-01-01 13:00:00-05:00], ordered=True, dtype='category')""" # noqa:E501 assert repr(i) == exp @@ -446,24 +446,24 @@ def test_categorical_index_repr_period(self): # test all length idx = period_range("2011-01-01 09:00", freq="H", periods=1) i = CategoricalIndex(Categorical(idx)) - exp = """CategoricalIndex(['2011-01-01 09:00'], categories=[2011-01-01 09:00], ordered=False, dtype='category')""" # noqa + exp = """CategoricalIndex(['2011-01-01 09:00'], categories=[2011-01-01 09:00], ordered=False, dtype='category')""" # noqa:E501 assert repr(i) == exp idx = period_range("2011-01-01 09:00", freq="H", periods=2) i = CategoricalIndex(Categorical(idx)) - exp = """CategoricalIndex(['2011-01-01 09:00', '2011-01-01 10:00'], categories=[2011-01-01 09:00, 2011-01-01 10:00], ordered=False, dtype='category')""" # noqa + exp = """CategoricalIndex(['2011-01-01 09:00', '2011-01-01 10:00'], categories=[2011-01-01 09:00, 2011-01-01 10:00], ordered=False, dtype='category')""" # noqa:E501 assert repr(i) == exp idx = period_range("2011-01-01 09:00", freq="H", periods=3) i = CategoricalIndex(Categorical(idx)) - exp = """CategoricalIndex(['2011-01-01 09:00', '2011-01-01 10:00', '2011-01-01 11:00'], categories=[2011-01-01 09:00, 2011-01-01 10:00, 2011-01-01 11:00], ordered=False, dtype='category')""" # noqa + exp = """CategoricalIndex(['2011-01-01 09:00', '2011-01-01 10:00', '2011-01-01 11:00'], categories=[2011-01-01 09:00, 2011-01-01 10:00, 2011-01-01 11:00], ordered=False, dtype='category')""" # noqa:E501 assert repr(i) == exp idx = period_range("2011-01-01 09:00", freq="H", periods=5) i = CategoricalIndex(Categorical(idx)) exp = """CategoricalIndex(['2011-01-01 09:00', '2011-01-01 10:00', '2011-01-01 11:00', '2011-01-01 12:00', '2011-01-01 13:00'], - categories=[2011-01-01 09:00, 2011-01-01 10:00, 2011-01-01 11:00, 2011-01-01 12:00, 2011-01-01 13:00], ordered=False, dtype='category')""" # noqa + categories=[2011-01-01 09:00, 2011-01-01 10:00, 2011-01-01 11:00, 2011-01-01 12:00, 2011-01-01 13:00], ordered=False, dtype='category')""" # noqa:E501 assert repr(i) == exp @@ -472,13 +472,13 @@ def test_categorical_index_repr_period(self): '2011-01-01 12:00', '2011-01-01 13:00', '2011-01-01 09:00', '2011-01-01 10:00', '2011-01-01 11:00', '2011-01-01 12:00', '2011-01-01 13:00'], - categories=[2011-01-01 09:00, 2011-01-01 10:00, 2011-01-01 11:00, 2011-01-01 12:00, 2011-01-01 13:00], ordered=False, dtype='category')""" # noqa + categories=[2011-01-01 09:00, 2011-01-01 10:00, 2011-01-01 11:00, 2011-01-01 12:00, 2011-01-01 13:00], ordered=False, dtype='category')""" # noqa:E501 assert repr(i) == exp idx = period_range("2011-01", freq="M", periods=5) i = CategoricalIndex(Categorical(idx)) - exp = """CategoricalIndex(['2011-01', '2011-02', '2011-03', '2011-04', '2011-05'], categories=[2011-01, 2011-02, 2011-03, 2011-04, 2011-05], ordered=False, dtype='category')""" # noqa + exp = """CategoricalIndex(['2011-01', '2011-02', '2011-03', '2011-04', '2011-05'], categories=[2011-01, 2011-02, 2011-03, 2011-04, 2011-05], ordered=False, dtype='category')""" # noqa:E501 assert repr(i) == exp def test_categorical_index_repr_period_ordered(self): @@ -486,19 +486,19 @@ def test_categorical_index_repr_period_ordered(self): i = CategoricalIndex(Categorical(idx, ordered=True)) exp = """CategoricalIndex(['2011-01-01 09:00', '2011-01-01 10:00', '2011-01-01 11:00', '2011-01-01 12:00', '2011-01-01 13:00'], - categories=[2011-01-01 09:00, 2011-01-01 10:00, 2011-01-01 11:00, 2011-01-01 12:00, 2011-01-01 13:00], ordered=True, dtype='category')""" # noqa + categories=[2011-01-01 09:00, 2011-01-01 10:00, 2011-01-01 11:00, 2011-01-01 12:00, 2011-01-01 13:00], ordered=True, dtype='category')""" # noqa:E501 assert repr(i) == exp idx = period_range("2011-01", freq="M", periods=5) i = CategoricalIndex(Categorical(idx, ordered=True)) - exp = """CategoricalIndex(['2011-01', '2011-02', '2011-03', '2011-04', '2011-05'], categories=[2011-01, 2011-02, 2011-03, 2011-04, 2011-05], ordered=True, dtype='category')""" # noqa + exp = """CategoricalIndex(['2011-01', '2011-02', '2011-03', '2011-04', '2011-05'], categories=[2011-01, 2011-02, 2011-03, 2011-04, 2011-05], ordered=True, dtype='category')""" # noqa:E501 assert repr(i) == exp def test_categorical_index_repr_timedelta(self): idx = timedelta_range("1 days", periods=5) i = CategoricalIndex(Categorical(idx)) - exp = """CategoricalIndex(['1 days', '2 days', '3 days', '4 days', '5 days'], categories=[1 days 00:00:00, 2 days 00:00:00, 3 days 00:00:00, 4 days 00:00:00, 5 days 00:00:00], ordered=False, dtype='category')""" # noqa + exp = """CategoricalIndex(['1 days', '2 days', '3 days', '4 days', '5 days'], categories=[1 days 00:00:00, 2 days 00:00:00, 3 days 00:00:00, 4 days 00:00:00, 5 days 00:00:00], ordered=False, dtype='category')""" # noqa:E501 assert repr(i) == exp idx = timedelta_range("1 hours", periods=10) @@ -507,14 +507,14 @@ def test_categorical_index_repr_timedelta(self): '3 days 01:00:00', '4 days 01:00:00', '5 days 01:00:00', '6 days 01:00:00', '7 days 01:00:00', '8 days 01:00:00', '9 days 01:00:00'], - categories=[0 days 01:00:00, 1 days 01:00:00, 2 days 01:00:00, 3 days 01:00:00, 4 days 01:00:00, 5 days 01:00:00, 6 days 01:00:00, 7 days 01:00:00, ...], ordered=False, dtype='category')""" # noqa + categories=[0 days 01:00:00, 1 days 01:00:00, 2 days 01:00:00, 3 days 01:00:00, 4 days 01:00:00, 5 days 01:00:00, 6 days 01:00:00, 7 days 01:00:00, ...], ordered=False, dtype='category')""" # noqa:E501 assert repr(i) == exp def test_categorical_index_repr_timedelta_ordered(self): idx = timedelta_range("1 days", periods=5) i = CategoricalIndex(Categorical(idx, ordered=True)) - exp = """CategoricalIndex(['1 days', '2 days', '3 days', '4 days', '5 days'], categories=[1 days 00:00:00, 2 days 00:00:00, 3 days 00:00:00, 4 days 00:00:00, 5 days 00:00:00], ordered=True, dtype='category')""" # noqa + exp = """CategoricalIndex(['1 days', '2 days', '3 days', '4 days', '5 days'], categories=[1 days 00:00:00, 2 days 00:00:00, 3 days 00:00:00, 4 days 00:00:00, 5 days 00:00:00], ordered=True, dtype='category')""" # noqa:E501 assert repr(i) == exp idx = timedelta_range("1 hours", periods=10) @@ -523,7 +523,7 @@ def test_categorical_index_repr_timedelta_ordered(self): '3 days 01:00:00', '4 days 01:00:00', '5 days 01:00:00', '6 days 01:00:00', '7 days 01:00:00', '8 days 01:00:00', '9 days 01:00:00'], - categories=[0 days 01:00:00, 1 days 01:00:00, 2 days 01:00:00, 3 days 01:00:00, 4 days 01:00:00, 5 days 01:00:00, 6 days 01:00:00, 7 days 01:00:00, ...], ordered=True, dtype='category')""" # noqa + categories=[0 days 01:00:00, 1 days 01:00:00, 2 days 01:00:00, 3 days 01:00:00, 4 days 01:00:00, 5 days 01:00:00, 6 days 01:00:00, 7 days 01:00:00, ...], ordered=True, dtype='category')""" # noqa:E501 assert repr(i) == exp diff --git a/pandas/tests/arrays/floating/test_function.py b/pandas/tests/arrays/floating/test_function.py index ef95eac316397..ff84116fa1b18 100644 --- a/pandas/tests/arrays/floating/test_function.py +++ b/pandas/tests/arrays/floating/test_function.py @@ -106,16 +106,16 @@ def test_value_counts_na(): def test_value_counts_empty(): - s = pd.Series([], dtype="Float64") - result = s.value_counts() + ser = pd.Series([], dtype="Float64") + result = ser.value_counts() idx = pd.Index([], dtype="object") expected = pd.Series([], index=idx, dtype="Int64") tm.assert_series_equal(result, expected) def test_value_counts_with_normalize(): - s = pd.Series([0.1, 0.2, 0.1, pd.NA], dtype="Float64") - result = s.value_counts(normalize=True) + ser = pd.Series([0.1, 0.2, 0.1, pd.NA], dtype="Float64") + result = ser.value_counts(normalize=True) expected = pd.Series([2, 1], index=[0.1, 0.2], dtype="Float64") / 3 tm.assert_series_equal(result, expected) diff --git a/pandas/tests/arrays/integer/test_function.py b/pandas/tests/arrays/integer/test_function.py index 6f53b44776900..3d8c93fbd507f 100644 --- a/pandas/tests/arrays/integer/test_function.py +++ b/pandas/tests/arrays/integer/test_function.py @@ -118,8 +118,8 @@ def test_value_counts_na(): def test_value_counts_empty(): # https://github.com/pandas-dev/pandas/issues/33317 - s = pd.Series([], dtype="Int64") - result = s.value_counts() + ser = pd.Series([], dtype="Int64") + result = ser.value_counts() # TODO: The dtype of the index seems wrong (it's int64 for non-empty) idx = pd.Index([], dtype="object") expected = pd.Series([], index=idx, dtype="Int64") @@ -128,8 +128,8 @@ def test_value_counts_empty(): def test_value_counts_with_normalize(): # GH 33172 - s = pd.Series([1, 2, 1, pd.NA], dtype="Int64") - result = s.value_counts(normalize=True) + ser = pd.Series([1, 2, 1, pd.NA], dtype="Int64") + result = ser.value_counts(normalize=True) expected = pd.Series([2, 1], index=[1, 2], dtype="Float64") / 3 tm.assert_series_equal(result, expected) diff --git a/pandas/tests/arrays/string_/test_string.py b/pandas/tests/arrays/string_/test_string.py index 501a79a8bc5ed..092fc6a460fca 100644 --- a/pandas/tests/arrays/string_/test_string.py +++ b/pandas/tests/arrays/string_/test_string.py @@ -475,8 +475,8 @@ def test_value_counts_na(dtype): def test_value_counts_with_normalize(dtype): - s = pd.Series(["a", "b", "a", pd.NA], dtype=dtype) - result = s.value_counts(normalize=True) + ser = pd.Series(["a", "b", "a", pd.NA], dtype=dtype) + result = ser.value_counts(normalize=True) expected = pd.Series([2, 1], index=["a", "b"], dtype="Float64") / 3 tm.assert_series_equal(result, expected) @@ -518,8 +518,8 @@ def test_memory_usage(dtype): @pytest.mark.parametrize("float_dtype", [np.float16, np.float32, np.float64]) def test_astype_from_float_dtype(float_dtype, dtype): # https://github.com/pandas-dev/pandas/issues/36451 - s = pd.Series([0.1], dtype=float_dtype) - result = s.astype(dtype) + ser = pd.Series([0.1], dtype=float_dtype) + result = ser.astype(dtype) expected = pd.Series(["0.1"], dtype=dtype) tm.assert_series_equal(result, expected) diff --git a/pandas/tests/computation/test_compat.py b/pandas/tests/computation/test_compat.py index 6d6aa08204c3f..5e76fa4cbdb4f 100644 --- a/pandas/tests/computation/test_compat.py +++ b/pandas/tests/computation/test_compat.py @@ -29,13 +29,13 @@ def test_compat(): @pytest.mark.parametrize("parser", expr.PARSERS) def test_invalid_numexpr_version(engine, parser): def testit(): - a, b = 1, 2 # noqa + a, b = 1, 2 # noqa:F841 res = pd.eval("a + b", engine=engine, parser=parser) assert res == 3 if engine == "numexpr": try: - import numexpr as ne # noqa F401 + import numexpr as ne # noqa:F401 except ImportError: pytest.skip("no numexpr") else: diff --git a/pandas/tests/computation/test_eval.py b/pandas/tests/computation/test_eval.py index dfdb9dabf6bed..5c614dac2bcb9 100644 --- a/pandas/tests/computation/test_eval.py +++ b/pandas/tests/computation/test_eval.py @@ -704,7 +704,7 @@ def test_identical(self): tm.assert_numpy_array_equal(result, np.array([1.5])) assert result.shape == (1,) - x = np.array([False]) # noqa + x = np.array([False]) # noqa:F841 result = pd.eval("x", engine=self.engine, parser=self.parser) tm.assert_numpy_array_equal(result, np.array([False])) assert result.shape == (1,) @@ -1239,7 +1239,7 @@ def test_truediv(self): assert res == expec def test_failing_subscript_with_name_error(self): - df = DataFrame(np.random.randn(5, 3)) # noqa + df = DataFrame(np.random.randn(5, 3)) # noqa:F841 with pytest.raises(NameError, match="name 'x' is not defined"): self.eval("df[x > 2] > 2") @@ -1304,7 +1304,7 @@ def test_assignment_column(self): # with a local name overlap def f(): df = orig_df.copy() - a = 1 # noqa + a = 1 # noqa:F841 df.eval("a = 1 + b", inplace=True) return df @@ -1316,7 +1316,7 @@ def f(): df = orig_df.copy() def f(): - a = 1 # noqa + a = 1 # noqa:F841 old_a = df.a.copy() df.eval("a = a + b", inplace=True) result = old_a + df.b @@ -1629,7 +1629,7 @@ class TestOperationsNumExprPython(TestOperationsNumExprPandas): parser = "python" def test_check_many_exprs(self): - a = 1 # noqa + a = 1 # noqa:F841 expr = " * ".join("a" * 33) expected = 1 res = pd.eval(expr, engine=self.engine, parser=self.parser) @@ -1669,14 +1669,14 @@ def test_fails_not(self): ) def test_fails_ampersand(self): - df = DataFrame(np.random.randn(5, 3)) # noqa + df = DataFrame(np.random.randn(5, 3)) # noqa:F841 ex = "(df + 2)[df > 1] > 0 & (df > 0)" msg = "cannot evaluate scalar only bool ops" with pytest.raises(NotImplementedError, match=msg): pd.eval(ex, parser=self.parser, engine=self.engine) def test_fails_pipe(self): - df = DataFrame(np.random.randn(5, 3)) # noqa + df = DataFrame(np.random.randn(5, 3)) # noqa:F841 ex = "(df + 2)[df > 1] > 0 | (df > 0)" msg = "cannot evaluate scalar only bool ops" with pytest.raises(NotImplementedError, match=msg): @@ -1851,7 +1851,7 @@ def test_no_new_locals(self, engine, parser): assert lcls == lcls2 def test_no_new_globals(self, engine, parser): - x = 1 # noqa + x = 1 # noqa:F841 gbls = globals().copy() pd.eval("x + 1", engine=engine, parser=parser) gbls2 = globals().copy() @@ -1936,7 +1936,7 @@ def test_name_error_exprs(engine, parser): @pytest.mark.parametrize("express", ["a + @b", "@a + b", "@a + @b"]) def test_invalid_local_variable_reference(engine, parser, express): - a, b = 1, 2 # noqa + a, b = 1, 2 # noqa:F841 if parser != "pandas": with pytest.raises(SyntaxError, match="The '@' prefix is only"): @@ -1980,7 +1980,7 @@ def test_more_than_one_expression_raises(engine, parser): def test_bool_ops_fails_on_scalars(lhs, cmp, rhs, engine, parser): gen = {int: lambda: np.random.randint(10), float: np.random.randn} - mid = gen[lhs]() # noqa + mid = gen[lhs]() # noqa:F841 lhs = gen[lhs]() rhs = gen[rhs]() diff --git a/pandas/tests/frame/test_query_eval.py b/pandas/tests/frame/test_query_eval.py index f7eb9dfccc382..331c21de8e4bd 100644 --- a/pandas/tests/frame/test_query_eval.py +++ b/pandas/tests/frame/test_query_eval.py @@ -109,7 +109,7 @@ def test_ops(self, op_str, op, rop, n): df.iloc[0] = 2 m = df.mean() - base = DataFrame( # noqa + base = DataFrame( # noqa:F841 np.tile(m.values, n).reshape(n, -1), columns=list("abcd") ) @@ -492,7 +492,7 @@ def test_query_scope(self): df = DataFrame(np.random.randn(20, 2), columns=list("ab")) - a, b = 1, 2 # noqa + a, b = 1, 2 # noqa:F841 res = df.query("a > b", engine=engine, parser=parser) expected = df[df.a > df.b] tm.assert_frame_equal(res, expected) @@ -661,7 +661,7 @@ def test_local_variable_with_in(self): def test_at_inside_string(self): engine, parser = self.engine, self.parser skip_if_no_pandas_parser(parser) - c = 1 # noqa + c = 1 # noqa:F841 df = DataFrame({"a": ["a", "a", "b", "b", "@c", "@c"]}) result = df.query('a == "@c"', engine=engine, parser=parser) expected = df[df.a == "@c"] @@ -680,7 +680,7 @@ def test_query_undefined_local(self): df.query("a == @c", engine=engine, parser=parser) def test_index_resolvers_come_after_columns_with_the_same_name(self): - n = 1 # noqa + n = 1 # noqa:F841 a = np.r_[20:101:20] df = DataFrame({"index": a, "b": np.random.randn(a.size)}) @@ -834,7 +834,7 @@ def test_nested_scope(self): engine = self.engine parser = self.parser # smoke test - x = 1 # noqa + x = 1 # noqa:F841 result = pd.eval("x + 1", engine=engine, parser=parser) assert result == 2 @@ -1073,7 +1073,7 @@ def test_query_string_scalar_variable(self, parser, engine): } ) e = df[df.Symbol == "BUD US"] - symb = "BUD US" # noqa + symb = "BUD US" # noqa:F841 r = df.query("Symbol == @symb", parser=parser, engine=engine) tm.assert_frame_equal(e, r) @@ -1255,7 +1255,7 @@ def test_call_non_named_expression(self, df): def func(*_): return 1 - funcs = [func] # noqa + funcs = [func] # noqa:F841 df.eval("@func()") diff --git a/pandas/tests/indexes/categorical/test_formats.py b/pandas/tests/indexes/categorical/test_formats.py index 98948c2113bbe..044b03579d535 100644 --- a/pandas/tests/indexes/categorical/test_formats.py +++ b/pandas/tests/indexes/categorical/test_formats.py @@ -16,7 +16,7 @@ def test_format_different_scalar_lengths(self): def test_string_categorical_index_repr(self): # short idx = CategoricalIndex(["a", "bb", "ccc"]) - expected = """CategoricalIndex(['a', 'bb', 'ccc'], categories=['a', 'bb', 'ccc'], ordered=False, dtype='category')""" # noqa + expected = """CategoricalIndex(['a', 'bb', 'ccc'], categories=['a', 'bb', 'ccc'], ordered=False, dtype='category')""" # noqa:E501 assert repr(idx) == expected # multiple lines @@ -33,7 +33,7 @@ def test_string_categorical_index_repr(self): expected = """CategoricalIndex(['a', 'bb', 'ccc', 'a', 'bb', 'ccc', 'a', 'bb', 'ccc', 'a', ... 'ccc', 'a', 'bb', 'ccc', 'a', 'bb', 'ccc', 'a', 'bb', 'ccc'], - categories=['a', 'bb', 'ccc'], ordered=False, dtype='category', length=300)""" # noqa + categories=['a', 'bb', 'ccc'], ordered=False, dtype='category', length=300)""" # noqa:E501 assert repr(idx) == expected @@ -41,13 +41,13 @@ def test_string_categorical_index_repr(self): idx = CategoricalIndex(list("abcdefghijklmmo")) expected = """CategoricalIndex(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'm', 'o'], - categories=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', ...], ordered=False, dtype='category')""" # noqa + categories=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', ...], ordered=False, dtype='category')""" # noqa:E501 assert repr(idx) == expected # short idx = CategoricalIndex(["あ", "いい", "ううう"]) - expected = """CategoricalIndex(['あ', 'いい', 'ううう'], categories=['あ', 'いい', 'ううう'], ordered=False, dtype='category')""" # noqa + expected = """CategoricalIndex(['あ', 'いい', 'ううう'], categories=['あ', 'いい', 'ううう'], ordered=False, dtype='category')""" # noqa:E501 assert repr(idx) == expected # multiple lines @@ -64,7 +64,7 @@ def test_string_categorical_index_repr(self): expected = """CategoricalIndex(['あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', ... 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう'], - categories=['あ', 'いい', 'ううう'], ordered=False, dtype='category', length=300)""" # noqa + categories=['あ', 'いい', 'ううう'], ordered=False, dtype='category', length=300)""" # noqa:E501 assert repr(idx) == expected @@ -72,7 +72,7 @@ def test_string_categorical_index_repr(self): idx = CategoricalIndex(list("あいうえおかきくけこさしすせそ")) expected = """CategoricalIndex(['あ', 'い', 'う', 'え', 'お', 'か', 'き', 'く', 'け', 'こ', 'さ', 'し', 'す', 'せ', 'そ'], - categories=['あ', 'い', 'う', 'え', 'お', 'か', 'き', 'く', ...], ordered=False, dtype='category')""" # noqa + categories=['あ', 'い', 'う', 'え', 'お', 'か', 'き', 'く', ...], ordered=False, dtype='category')""" # noqa:E501 assert repr(idx) == expected @@ -81,7 +81,7 @@ def test_string_categorical_index_repr(self): # short idx = CategoricalIndex(["あ", "いい", "ううう"]) - expected = """CategoricalIndex(['あ', 'いい', 'ううう'], categories=['あ', 'いい', 'ううう'], ordered=False, dtype='category')""" # noqa + expected = """CategoricalIndex(['あ', 'いい', 'ううう'], categories=['あ', 'いい', 'ううう'], ordered=False, dtype='category')""" # noqa:E501 assert repr(idx) == expected # multiple lines @@ -101,7 +101,7 @@ def test_string_categorical_index_repr(self): ... 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう'], - categories=['あ', 'いい', 'ううう'], ordered=False, dtype='category', length=300)""" # noqa + categories=['あ', 'いい', 'ううう'], ordered=False, dtype='category', length=300)""" # noqa:E501 assert repr(idx) == expected @@ -109,6 +109,6 @@ def test_string_categorical_index_repr(self): idx = CategoricalIndex(list("あいうえおかきくけこさしすせそ")) expected = """CategoricalIndex(['あ', 'い', 'う', 'え', 'お', 'か', 'き', 'く', 'け', 'こ', 'さ', 'し', 'す', 'せ', 'そ'], - categories=['あ', 'い', 'う', 'え', 'お', 'か', 'き', 'く', ...], ordered=False, dtype='category')""" # noqa + categories=['あ', 'い', 'う', 'え', 'お', 'か', 'き', 'く', ...], ordered=False, dtype='category')""" # noqa:E501 assert repr(idx) == expected diff --git a/pandas/tests/indexing/multiindex/test_setitem.py b/pandas/tests/indexing/multiindex/test_setitem.py index b97aaf6c551d8..2a12d690ff0bd 100644 --- a/pandas/tests/indexing/multiindex/test_setitem.py +++ b/pandas/tests/indexing/multiindex/test_setitem.py @@ -368,8 +368,7 @@ def test_frame_setitem_multi_column2(self): assert sliced_a2.name == ("A", "2") assert sliced_b1.name == ("B", "1") - # TODO: no setitem here? - def test_getitem_setitem_tuple_plus_columns( + def test_loc_getitem_tuple_plus_columns( self, multiindex_year_month_day_dataframe_random_data ): # GH #1013 diff --git a/pandas/tests/io/conftest.py b/pandas/tests/io/conftest.py index 5d4705dbe7d77..8c34ca8056a07 100644 --- a/pandas/tests/io/conftest.py +++ b/pandas/tests/io/conftest.py @@ -131,12 +131,12 @@ def add_tips_files(bucket_name): try: cli.create_bucket(Bucket=bucket) - except: # noqa + except Exception: # OK is bucket already exists pass try: cli.create_bucket(Bucket="cant_get_it", ACL="private") - except: # noqa + except Exception: # OK is bucket already exists pass timeout = 2 @@ -153,11 +153,11 @@ def add_tips_files(bucket_name): try: s3.rm(bucket, recursive=True) - except: # noqa + except Exception: pass try: s3.rm("cant_get_it", recursive=True) - except: # noqa + except Exception: pass timeout = 2 while cli.list_buckets()["Buckets"] and timeout > 0: diff --git a/pandas/tests/io/parser/common/test_common_basic.py b/pandas/tests/io/parser/common/test_common_basic.py index 6d958f46a49dd..96c3709fdb3d8 100644 --- a/pandas/tests/io/parser/common/test_common_basic.py +++ b/pandas/tests/io/parser/common/test_common_basic.py @@ -385,7 +385,7 @@ def test_escapechar(all_parsers): data = '''SEARCH_TERM,ACTUAL_URL "bra tv board","http://www.ikea.com/se/sv/catalog/categories/departments/living_room/10475/?se%7cps%7cnonbranded%7cvardagsrum%7cgoogle%7ctv_bord" "tv p\xc3\xa5 hjul","http://www.ikea.com/se/sv/catalog/categories/departments/living_room/10475/?se%7cps%7cnonbranded%7cvardagsrum%7cgoogle%7ctv_bord" -"SLAGBORD, \\"Bergslagen\\", IKEA:s 1700-tals series","http://www.ikea.com/se/sv/catalog/categories/departments/living_room/10475/?se%7cps%7cnonbranded%7cvardagsrum%7cgoogle%7ctv_bord"''' # noqa +"SLAGBORD, \\"Bergslagen\\", IKEA:s 1700-tals series","http://www.ikea.com/se/sv/catalog/categories/departments/living_room/10475/?se%7cps%7cnonbranded%7cvardagsrum%7cgoogle%7ctv_bord"''' # noqa:E501 parser = all_parsers result = parser.read_csv( @@ -491,7 +491,7 @@ def test_read_empty_with_usecols(all_parsers, data, kwargs, expected): ], ) def test_trailing_spaces(all_parsers, kwargs, expected): - data = "A B C \nrandom line with trailing spaces \nskip\n1,2,3\n1,2.,4.\nrandom line with trailing tabs\t\t\t\n \n5.1,NaN,10.0\n" # noqa + data = "A B C \nrandom line with trailing spaces \nskip\n1,2,3\n1,2.,4.\nrandom line with trailing tabs\t\t\t\n \n5.1,NaN,10.0\n" # noqa:E501 parser = all_parsers result = parser.read_csv(StringIO(data.replace(",", " ")), **kwargs) diff --git a/pandas/tests/io/parser/test_read_fwf.py b/pandas/tests/io/parser/test_read_fwf.py index d4e33543d8a04..910731bd7dde2 100644 --- a/pandas/tests/io/parser/test_read_fwf.py +++ b/pandas/tests/io/parser/test_read_fwf.py @@ -311,7 +311,7 @@ def test_fwf_regression(): def test_fwf_for_uint8(): data = """1421302965.213420 PRI=3 PGN=0xef00 DST=0x17 SRC=0x28 04 154 00 00 00 00 00 127 -1421302964.226776 PRI=6 PGN=0xf002 SRC=0x47 243 00 00 255 247 00 00 71""" # noqa +1421302964.226776 PRI=6 PGN=0xf002 SRC=0x47 243 00 00 255 247 00 00 71""" # noqa:E501 df = read_fwf( StringIO(data), colspecs=[(0, 17), (25, 26), (33, 37), (49, 51), (58, 62), (63, 1000)], diff --git a/pandas/tests/io/test_stata.py b/pandas/tests/io/test_stata.py index f4f79c915b317..fa2305d11f901 100644 --- a/pandas/tests/io/test_stata.py +++ b/pandas/tests/io/test_stata.py @@ -1135,7 +1135,7 @@ def test_read_chunks_117( ): fname = getattr(self, file) - with warnings.catch_warnings(record=True) as w: + with warnings.catch_warnings(record=True): warnings.simplefilter("always") parsed = read_stata( fname, @@ -1151,7 +1151,7 @@ def test_read_chunks_117( pos = 0 for j in range(5): - with warnings.catch_warnings(record=True) as w: # noqa + with warnings.catch_warnings(record=True): warnings.simplefilter("always") try: chunk = itr.read(chunksize) @@ -1232,7 +1232,7 @@ def test_read_chunks_115( fname = getattr(self, file) # Read the whole file - with warnings.catch_warnings(record=True) as w: + with warnings.catch_warnings(record=True): warnings.simplefilter("always") parsed = read_stata( fname, @@ -1249,7 +1249,7 @@ def test_read_chunks_115( ) pos = 0 for j in range(5): - with warnings.catch_warnings(record=True) as w: # noqa + with warnings.catch_warnings(record=True): warnings.simplefilter("always") try: chunk = itr.read(chunksize) diff --git a/pandas/tests/plotting/test_series.py b/pandas/tests/plotting/test_series.py index e40798f4f5125..5a80df8d6c779 100644 --- a/pandas/tests/plotting/test_series.py +++ b/pandas/tests/plotting/test_series.py @@ -720,7 +720,7 @@ def test_custom_business_day_freq(self): _check_plot_works(s.plot) - @pytest.mark.xfail + @pytest.mark.xfail(reason="TODO: reason?") def test_plot_accessor_updates_on_inplace(self): s = Series([1, 2, 3, 4]) _, ax = self.plt.subplots() diff --git a/pandas/tests/resample/test_base.py b/pandas/tests/resample/test_base.py index 450bd8b05ea43..2dae9ee48a90a 100644 --- a/pandas/tests/resample/test_base.py +++ b/pandas/tests/resample/test_base.py @@ -20,7 +20,7 @@ # a fixture value can be overridden by the test parameter value. Note that the # value of the fixture can be overridden this way even if the test doesn't use # it directly (doesn't mention it in the function prototype). -# see https://docs.pytest.org/en/latest/fixture.html#override-a-fixture-with-direct-test-parametrization # noqa +# see https://docs.pytest.org/en/latest/fixture.html#override-a-fixture-with-direct-test-parametrization # noqa:E501 # in this module we override the fixture values defined in conftest.py # tuples of '_index_factory,_series_name,_index_start,_index_end' DATE_RANGE = (date_range, "dti", datetime(2005, 1, 1), datetime(2005, 1, 10)) diff --git a/pandas/tests/series/methods/test_astype.py b/pandas/tests/series/methods/test_astype.py index 732d375d136d0..a20667655590b 100644 --- a/pandas/tests/series/methods/test_astype.py +++ b/pandas/tests/series/methods/test_astype.py @@ -128,7 +128,7 @@ def test_astype_no_pandas_dtype(self): def test_astype_generic_timestamp_no_frequency(self, dtype, request): # see GH#15524, GH#15987 data = [1] - s = Series(data) + ser = Series(data) if np.dtype(dtype).name not in ["timedelta64", "datetime64"]: mark = pytest.mark.xfail(reason="GH#33890 Is assigned ns unit") @@ -139,7 +139,7 @@ def test_astype_generic_timestamp_no_frequency(self, dtype, request): fr"Please pass in '{dtype.__name__}\[ns\]' instead." ) with pytest.raises(ValueError, match=msg): - s.astype(dtype) + ser.astype(dtype) def test_astype_dt64_to_str(self): # GH#10442 : testing astype(str) is correct for Series/DatetimeIndex diff --git a/pandas/tests/series/test_repr.py b/pandas/tests/series/test_repr.py index 555342dd39005..d3ff7f4dc7b4c 100644 --- a/pandas/tests/series/test_repr.py +++ b/pandas/tests/series/test_repr.py @@ -355,7 +355,7 @@ def test_categorical_series_repr_datetime(self): 4 2011-01-01 13:00:00 dtype: category Categories (5, datetime64[ns]): [2011-01-01 09:00:00, 2011-01-01 10:00:00, 2011-01-01 11:00:00, - 2011-01-01 12:00:00, 2011-01-01 13:00:00]""" # noqa + 2011-01-01 12:00:00, 2011-01-01 13:00:00]""" # noqa:E501 assert repr(s) == exp @@ -369,7 +369,7 @@ def test_categorical_series_repr_datetime(self): dtype: category Categories (5, datetime64[ns, US/Eastern]): [2011-01-01 09:00:00-05:00, 2011-01-01 10:00:00-05:00, 2011-01-01 11:00:00-05:00, 2011-01-01 12:00:00-05:00, - 2011-01-01 13:00:00-05:00]""" # noqa + 2011-01-01 13:00:00-05:00]""" # noqa:E501 assert repr(s) == exp @@ -383,7 +383,7 @@ def test_categorical_series_repr_datetime_ordered(self): 4 2011-01-01 13:00:00 dtype: category Categories (5, datetime64[ns]): [2011-01-01 09:00:00 < 2011-01-01 10:00:00 < 2011-01-01 11:00:00 < - 2011-01-01 12:00:00 < 2011-01-01 13:00:00]""" # noqa + 2011-01-01 12:00:00 < 2011-01-01 13:00:00]""" # noqa:E501 assert repr(s) == exp @@ -397,7 +397,7 @@ def test_categorical_series_repr_datetime_ordered(self): dtype: category Categories (5, datetime64[ns, US/Eastern]): [2011-01-01 09:00:00-05:00 < 2011-01-01 10:00:00-05:00 < 2011-01-01 11:00:00-05:00 < 2011-01-01 12:00:00-05:00 < - 2011-01-01 13:00:00-05:00]""" # noqa + 2011-01-01 13:00:00-05:00]""" # noqa:E501 assert repr(s) == exp @@ -411,7 +411,7 @@ def test_categorical_series_repr_period(self): 4 2011-01-01 13:00 dtype: category Categories (5, period[H]): [2011-01-01 09:00, 2011-01-01 10:00, 2011-01-01 11:00, 2011-01-01 12:00, - 2011-01-01 13:00]""" # noqa + 2011-01-01 13:00]""" # noqa:E501 assert repr(s) == exp @@ -437,7 +437,7 @@ def test_categorical_series_repr_period_ordered(self): 4 2011-01-01 13:00 dtype: category Categories (5, period[H]): [2011-01-01 09:00 < 2011-01-01 10:00 < 2011-01-01 11:00 < 2011-01-01 12:00 < - 2011-01-01 13:00]""" # noqa + 2011-01-01 13:00]""" # noqa:E501 assert repr(s) == exp @@ -481,7 +481,7 @@ def test_categorical_series_repr_timedelta(self): dtype: category Categories (10, timedelta64[ns]): [0 days 01:00:00, 1 days 01:00:00, 2 days 01:00:00, 3 days 01:00:00, ..., 6 days 01:00:00, 7 days 01:00:00, - 8 days 01:00:00, 9 days 01:00:00]""" # noqa + 8 days 01:00:00, 9 days 01:00:00]""" # noqa:E501 assert repr(s) == exp @@ -513,6 +513,6 @@ def test_categorical_series_repr_timedelta_ordered(self): dtype: category Categories (10, timedelta64[ns]): [0 days 01:00:00 < 1 days 01:00:00 < 2 days 01:00:00 < 3 days 01:00:00 ... 6 days 01:00:00 < 7 days 01:00:00 < - 8 days 01:00:00 < 9 days 01:00:00]""" # noqa + 8 days 01:00:00 < 9 days 01:00:00]""" # noqa:E501 assert repr(s) == exp diff --git a/pandas/tests/test_downstream.py b/pandas/tests/test_downstream.py index f927a0ec0927b..a15658ad43498 100644 --- a/pandas/tests/test_downstream.py +++ b/pandas/tests/test_downstream.py @@ -5,7 +5,7 @@ import subprocess import sys -import numpy as np # noqa +import numpy as np # noqa:F401 needed in namespace for statsmodels import pytest import pandas.util._test_decorators as td @@ -100,7 +100,7 @@ def test_oo_optimized_datetime_index_unpickle(): ) def test_statsmodels(): - statsmodels = import_module("statsmodels") # noqa + statsmodels = import_module("statsmodels") # noqa:F841 import statsmodels.api as sm import statsmodels.formula.api as smf diff --git a/pandas/tseries/api.py b/pandas/tseries/api.py index 2094791ecdc60..59666fa0048dd 100644 --- a/pandas/tseries/api.py +++ b/pandas/tseries/api.py @@ -2,7 +2,7 @@ Timeseries API """ -# flake8: noqa +# flake8: noqa:F401 from pandas.tseries.frequencies import infer_freq import pandas.tseries.offsets as offsets diff --git a/pandas/tseries/frequencies.py b/pandas/tseries/frequencies.py index fc01771507888..415af96a29aa3 100644 --- a/pandas/tseries/frequencies.py +++ b/pandas/tseries/frequencies.py @@ -399,10 +399,12 @@ def _is_business_daily(self) -> bool: shifts = np.diff(self.index.asi8) shifts = np.floor_divide(shifts, _ONE_DAY) weekdays = np.mod(first_weekday + np.cumsum(shifts), 7) - # error: Incompatible return value type (got "bool_", expected "bool") - return np.all( # type: ignore[return-value] - ((weekdays == 0) & (shifts == 3)) - | ((weekdays > 0) & (weekdays <= 4) & (shifts == 1)) + + return bool( + np.all( + ((weekdays == 0) & (shifts == 3)) + | ((weekdays > 0) & (weekdays <= 4) & (shifts == 1)) + ) ) def _get_wom_rule(self) -> str | None: diff --git a/pandas/util/__init__.py b/pandas/util/__init__.py index 35a88a802003e..7adfca73c2f1e 100644 --- a/pandas/util/__init__.py +++ b/pandas/util/__init__.py @@ -1,10 +1,10 @@ -from pandas.util._decorators import ( # noqa +from pandas.util._decorators import ( # noqa:F401 Appender, Substitution, cache_readonly, ) -from pandas.core.util.hashing import ( # noqa +from pandas.core.util.hashing import ( # noqa:F401 hash_array, hash_pandas_object, ) diff --git a/pandas/util/_decorators.py b/pandas/util/_decorators.py index d98b0d24d22b9..a936b8d1f585c 100644 --- a/pandas/util/_decorators.py +++ b/pandas/util/_decorators.py @@ -11,7 +11,7 @@ ) import warnings -from pandas._libs.properties import cache_readonly # noqa +from pandas._libs.properties import cache_readonly # noqa:F401 from pandas._typing import F diff --git a/pandas/util/_tester.py b/pandas/util/_tester.py index 1bdf0d8483c76..541776619a2d3 100644 --- a/pandas/util/_tester.py +++ b/pandas/util/_tester.py @@ -13,7 +13,7 @@ def test(extra_args=None): except ImportError as err: raise ImportError("Need pytest>=5.0.1 to run tests") from err try: - import hypothesis # noqa + import hypothesis # noqa:F401 except ImportError as err: raise ImportError("Need hypothesis>=3.58 to run tests") from err cmd = ["--skip-slow", "--skip-network", "--skip-db"] diff --git a/pandas/util/testing.py b/pandas/util/testing.py index 0ab59a202149d..db9bfc274cd78 100644 --- a/pandas/util/testing.py +++ b/pandas/util/testing.py @@ -2,7 +2,7 @@ from pandas.util._exceptions import find_stack_level -from pandas._testing import * # noqa +from pandas._testing import * # noqa:F401,F403,PDF014 warnings.warn( (