From c0df00a72d7b403a71eeed21ed67b63f23804da0 Mon Sep 17 00:00:00 2001 From: cmp0xff Date: Sat, 4 Oct 2025 12:29:02 +0200 Subject: [PATCH 1/4] chore(pyright): #1171 remove two strict rules --- pyrightconfig-strict.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pyrightconfig-strict.json b/pyrightconfig-strict.json index 4d5e9b0ed..60879d33f 100644 --- a/pyrightconfig-strict.json +++ b/pyrightconfig-strict.json @@ -5,5 +5,7 @@ "enableTypeIgnoreComments": false, "reportUnnecessaryTypeIgnoreComment": true, "reportMissingModuleSource": true, - "useLibraryCodeForTypes": false + "useLibraryCodeForTypes": false, + "reportPrivateUsage": false, + "reportUnknownLambdaType": false } From 7d3c15267921ad9661a38250de5a360becf62741 Mon Sep 17 00:00:00 2001 From: cmp0xff Date: Sat, 4 Oct 2025 19:01:57 +0200 Subject: [PATCH 2/4] fix(comment): https://github.com/pandas-dev/pandas-stubs/pull/1405#discussion_r2404081054 --- pyrightconfig-strict.json | 1 - 1 file changed, 1 deletion(-) diff --git a/pyrightconfig-strict.json b/pyrightconfig-strict.json index 60879d33f..3fae19695 100644 --- a/pyrightconfig-strict.json +++ b/pyrightconfig-strict.json @@ -6,6 +6,5 @@ "reportUnnecessaryTypeIgnoreComment": true, "reportMissingModuleSource": true, "useLibraryCodeForTypes": false, - "reportPrivateUsage": false, "reportUnknownLambdaType": false } From 7a711dad39fddf713b70134348370a57085e3b0f Mon Sep 17 00:00:00 2001 From: cmp0xff Date: Sat, 4 Oct 2025 19:05:17 +0200 Subject: [PATCH 3/4] fix: return None for tests --- tests/indexes/test_indexes.py | 20 +++--- tests/scalars/test_scalars.py | 2 +- tests/series/test_series.py | 4 +- tests/test_api_typing.py | 4 +- tests/test_config.py | 12 ++-- tests/test_frame.py | 12 ++-- tests/test_interval.py | 2 +- tests/test_io.py | 116 ++++++++++++++++----------------- tests/test_pandas.py | 8 +-- tests/test_plotting.py | 14 ++-- tests/test_string_accessors.py | 36 +++++----- tests/test_styler.py | 4 +- tests/test_testing.py | 4 +- tests/test_timefuncs.py | 6 +- tests/test_utility.py | 8 +-- 15 files changed, 126 insertions(+), 126 deletions(-) diff --git a/tests/indexes/test_indexes.py b/tests/indexes/test_indexes.py index af88f9116..2ba3c0bc4 100644 --- a/tests/indexes/test_indexes.py +++ b/tests/indexes/test_indexes.py @@ -223,7 +223,7 @@ def test_index_rename_inplace() -> None: assert ind2 is None -def test_index_dropna(): +def test_index_dropna() -> None: idx = pd.Index([1, 2]) check(assert_type(idx.dropna(how="all"), "pd.Index[int]"), pd.Index) @@ -235,7 +235,7 @@ def test_index_dropna(): check(assert_type(midx.dropna(how="any"), pd.MultiIndex), pd.MultiIndex) -def test_index_neg(): +def test_index_neg() -> None: # GH 253 idx = pd.Index([1, 2]) check(assert_type(-idx, "pd.Index[int]"), pd.Index) @@ -306,7 +306,7 @@ def test_index_relops() -> None: check(assert_type(ind > 2, np_1darray[np.bool]), np_1darray[np.bool]) -def test_range_index_union(): +def test_range_index_union() -> None: check( assert_type( pd.RangeIndex(0, 10).union(pd.RangeIndex(10, 20)), @@ -342,14 +342,14 @@ def test_index_union_sort() -> None: ) -def test_range_index_start_stop_step(): +def test_range_index_start_stop_step() -> None: idx = pd.RangeIndex(3) check(assert_type(idx.start, int), int) check(assert_type(idx.stop, int), int) check(assert_type(idx.step, int), int) -def test_interval_range(): +def test_interval_range() -> None: check( assert_type(pd.interval_range(0, 10), "pd.IntervalIndex[pd.Interval[int]]"), pd.IntervalIndex, @@ -502,7 +502,7 @@ def test_interval_range(): ) -def test_interval_index_breaks(): +def test_interval_index_breaks() -> None: check( assert_type( pd.IntervalIndex.from_breaks([1, 2, 3, 4]), @@ -632,7 +632,7 @@ def test_interval_index_breaks(): ) -def test_interval_index_arrays(): +def test_interval_index_arrays() -> None: check( assert_type( pd.IntervalIndex.from_arrays([1, 2, 3, 4], [2, 3, 4, 5]), @@ -761,7 +761,7 @@ def test_interval_index_arrays(): ) -def test_interval_index_tuples(): +def test_interval_index_tuples() -> None: check( assert_type( pd.IntervalIndex.from_tuples([(1, 2), (2, 3)]), @@ -1082,13 +1082,13 @@ def test_range_index_range() -> None: check(assert_type(iri, pd.RangeIndex), pd.RangeIndex, int) -def test_multiindex_dtypes(): +def test_multiindex_dtypes() -> None: # GH-597 mi = pd.MultiIndex.from_tuples([(1, 2.0), (2, 3.0)], names=["foo", "bar"]) check(assert_type(mi.dtypes, "pd.Series[Dtype]"), pd.Series) -def test_index_constructors(): +def test_index_constructors() -> None: # See if we can pick up the different index types in 2.0 # Eventually should be using a generic index ilist = [1, 2, 3] diff --git a/tests/scalars/test_scalars.py b/tests/scalars/test_scalars.py index 251dab4d3..c2cc3786a 100644 --- a/tests/scalars/test_scalars.py +++ b/tests/scalars/test_scalars.py @@ -297,7 +297,7 @@ def test_interval_math() -> None: ) # pyright: ignore[reportOperatorIssue] -def test_interval_cmp(): +def test_interval_cmp() -> None: interval_i = pd.Interval(0, 1, closed="left") interval_f = pd.Interval(0.0, 1.0, closed="right") interval_ts = pd.Interval( diff --git a/tests/series/test_series.py b/tests/series/test_series.py index 0f54a8a76..5bc6a26e2 100644 --- a/tests/series/test_series.py +++ b/tests/series/test_series.py @@ -1819,7 +1819,7 @@ def test_types_to_dict() -> None: assert_type(s.to_dict(), dict[Any, str]) -def test_categorical_codes(): +def test_categorical_codes() -> None: # GH-111 cat = pd.Categorical(["a", "b", "a"]) check(assert_type(cat.codes, np_1darray[np.signedinteger]), np_1darray[np.int8]) @@ -1942,7 +1942,7 @@ def test_squeeze() -> None: check(assert_type(s2.squeeze(), "pd.Series[int] | Scalar"), np.integer) -def test_to_xarray(): +def test_to_xarray() -> None: s = pd.Series([1, 2]) check(assert_type(s.to_xarray(), xr.DataArray), xr.DataArray) diff --git a/tests/test_api_typing.py b/tests/test_api_typing.py index 8140e778d..e9d014e57 100644 --- a/tests/test_api_typing.py +++ b/tests/test_api_typing.py @@ -42,7 +42,7 @@ ) -def test_dataframegroupby(): +def test_dataframegroupby() -> None: df = pd.DataFrame({"a": [1, 2, 3]}) group = df.groupby("a") @@ -52,7 +52,7 @@ def f1(gb: DataFrameGroupBy): f1(group) -def test_seriesgroupby(): +def test_seriesgroupby() -> None: sr = pd.Series([1, 2, 3], index=pd.Index(["a", "b", "a"])) def f1(gb: SeriesGroupBy): diff --git a/tests/test_config.py b/tests/test_config.py index a18773631..897527636 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -21,7 +21,7 @@ Display = Options = Any -def test_option_tools(): +def test_option_tools() -> None: check(assert_type(pd.reset_option("display.width"), None), type(None)) check(assert_type(pd.set_option("display.width", 80), None), type(None)) check(assert_type(pd.describe_option("display.width", False), str), str) @@ -33,14 +33,14 @@ def test_option_tools(): assert pd.get_option("display.width") == 120 -def test_specific_option(): +def test_specific_option() -> None: # GH 294 check(assert_type(pd.options.plotting.backend, str), str) # Just check assignment pd.options.plotting.backend = "matplotlib" -def test_display_float_format(): +def test_display_float_format() -> None: check( assert_type(pd.options.display.float_format, Callable[[float], str] | None), type(None), @@ -50,7 +50,7 @@ def test_display_float_format(): assert pd.get_option("display.float_format") == formatter -def test_display_types_none_allowed_get_options(): +def test_display_types_none_allowed_get_options() -> None: # GH 1230 # Initial values check(assert_type(pd.options.display.chop_threshold, float | None), type(None)) @@ -62,7 +62,7 @@ def test_display_types_none_allowed_get_options(): check(assert_type(pd.options.display.min_rows, int | None), int) -def test_display_types_none_allowed_set_options(): +def test_display_types_none_allowed_set_options() -> None: # GH 1230 # Test setting each option as None and then to a specific value pd.options.display.chop_threshold = None @@ -81,7 +81,7 @@ def test_display_types_none_allowed_set_options(): pd.options.display.min_rows = 100 -def test_display_types_literal_constraints(): +def test_display_types_literal_constraints() -> None: # GH 1230 # Various display options have specific allowed values # Test colheader_justify with allowed values diff --git a/tests/test_frame.py b/tests/test_frame.py index 82de306c3..8d2b95135 100644 --- a/tests/test_frame.py +++ b/tests/test_frame.py @@ -1512,7 +1512,7 @@ def test_types_pivot_table() -> None: ) -def test_pivot_table_sort(): +def test_pivot_table_sort() -> None: df = pd.DataFrame({"a": [1, 2], "b": [3, 4], "c": [5, 6], "d": [7, 8]}) check( @@ -2822,7 +2822,7 @@ def test_dataframe_pct_change() -> None: check(assert_type(df.pct_change(fill_value=0), pd.DataFrame), pd.DataFrame) -def test_indexslice_setitem(): +def test_indexslice_setitem() -> None: df = pd.DataFrame( {"x": [1, 2, 2, 3], "y": [1, 2, 3, 4], "z": [10, 20, 30, 40]} ).set_index(["x", "y"]) @@ -2833,7 +2833,7 @@ def test_indexslice_setitem(): df.loc[pd.IndexSlice[pd.Index([2, 3]), :], "z"] = 99 -def test_indexslice_getitem(): +def test_indexslice_getitem() -> None: # GH 300 df = ( pd.DataFrame({"x": [1, 2, 2, 3, 4], "y": [10, 20, 30, 40, 10]}) @@ -2865,7 +2865,7 @@ def test_indexslice_getitem(): ) -def test_compute_values(): +def test_compute_values() -> None: df = pd.DataFrame({"x": [1, 2, 3, 4]}) s: pd.Series = pd.Series([10, 20, 30, 40]) check(assert_type(df["x"] + s.values, pd.Series), pd.Series, np.int64) @@ -3295,7 +3295,7 @@ def test_not_hashable() -> None: check(assert_type(pd.Index.__hash__, None), type(None)) check(assert_type(pd.Index([]).__hash__, None), type(None)) - def test_func(_: Hashable): + def test_func(_: Hashable) -> None: pass if TYPE_CHECKING_INVALID_USAGE: @@ -3527,7 +3527,7 @@ def test_groupby_result_for_ambiguous_indexes() -> None: check(assert_type(value2, pd.DataFrame), pd.DataFrame) -def test_setitem_list(): +def test_setitem_list() -> None: # GH 153 lst1: list[str] = ["a", "b", "c"] lst2: list[int] = [1, 2, 3] diff --git a/tests/test_interval.py b/tests/test_interval.py index b3de71dac..40a8583bd 100644 --- a/tests/test_interval.py +++ b/tests/test_interval.py @@ -121,7 +121,7 @@ def test_interval_length() -> None: _21 = i3 + pd.Timedelta(seconds=20) # type: ignore[operator] # pyright: ignore[reportOperatorIssue] -def test_interval_array_contains(): +def test_interval_array_contains() -> None: df = pd.DataFrame({"A": range(1, 10)}) obj = pd.Interval(1, 4) ser = pd.Series(obj, index=df.index) diff --git a/tests/test_io.py b/tests/test_io.py index 343252740..513055531 100644 --- a/tests/test_io.py +++ b/tests/test_io.py @@ -69,14 +69,14 @@ @pytest.mark.skipif(WINDOWS, reason="ORC not available on windows") -def test_orc(): +def test_orc() -> None: with ensure_clean() as path: check(assert_type(DF.to_orc(path), None), type(None)) check(assert_type(read_orc(path), DataFrame), DataFrame) @pytest.mark.skipif(WINDOWS, reason="ORC not available on windows") -def test_orc_path(): +def test_orc_path() -> None: with ensure_clean() as path: pathlib_path = Path(path) check(assert_type(DF.to_orc(pathlib_path), None), type(None)) @@ -84,7 +84,7 @@ def test_orc_path(): @pytest.mark.skipif(WINDOWS, reason="ORC not available on windows") -def test_orc_buffer(): +def test_orc_buffer() -> None: with ensure_clean() as path: with open(path, "wb") as file_w: check(assert_type(DF.to_orc(file_w), None), type(None)) @@ -94,18 +94,18 @@ def test_orc_buffer(): @pytest.mark.skipif(WINDOWS, reason="ORC not available on windows") -def test_orc_columns(): +def test_orc_columns() -> None: with ensure_clean() as path: check(assert_type(DF.to_orc(path, index=False), None), type(None)) check(assert_type(read_orc(path, columns=["a"]), DataFrame), DataFrame) @pytest.mark.skipif(WINDOWS, reason="ORC not available on windows") -def test_orc_bytes(): +def test_orc_bytes() -> None: check(assert_type(DF.to_orc(index=False), bytes), bytes) -def test_xml(): +def test_xml() -> None: with ensure_clean() as path: check(assert_type(DF.to_xml(path), None), type(None)) check(assert_type(read_xml(path), DataFrame), DataFrame) @@ -113,38 +113,38 @@ def test_xml(): check(assert_type(read_xml(f), DataFrame), DataFrame) -def test_xml_str(): +def test_xml_str() -> None: with ensure_clean(): out = check(assert_type(DF.to_xml(), str), str) check(assert_type(read_xml(io.StringIO(out)), DataFrame), DataFrame) -def test_pickle(): +def test_pickle() -> None: with ensure_clean() as path: check(assert_type(DF.to_pickle(path), None), type(None)) check(assert_type(read_pickle(path), Any), DataFrame) -def test_pickle_file_handle(): +def test_pickle_file_handle() -> None: with ensure_clean() as path: check(assert_type(DF.to_pickle(path), None), type(None)) with open(path, "rb") as file: check(assert_type(read_pickle(file), Any), DataFrame) -def test_pickle_path(): +def test_pickle_path() -> None: with ensure_clean() as path: check(assert_type(DF.to_pickle(path), None), type(None)) check(assert_type(read_pickle(Path(path)), Any), DataFrame) -def test_pickle_protocol(): +def test_pickle_protocol() -> None: with ensure_clean() as path: DF.to_pickle(path, protocol=3) check(assert_type(read_pickle(path), Any), DataFrame) -def test_pickle_compression(): +def test_pickle_compression() -> None: with ensure_clean() as path: DF.to_pickle(path, compression="gzip") check( @@ -158,7 +158,7 @@ def test_pickle_compression(): ) -def test_pickle_storage_options(): +def test_pickle_storage_options() -> None: with ensure_clean() as path: DF.to_pickle(path, storage_options={}) @@ -168,20 +168,20 @@ def test_pickle_storage_options(): ) -def test_to_pickle_series(): +def test_to_pickle_series() -> None: s: Series = DF["a"] with ensure_clean() as path: check(assert_type(s.to_pickle(path), None), type(None)) check(assert_type(read_pickle(path), Any), Series) -def test_read_stata_df(): +def test_read_stata_df() -> None: with ensure_clean() as path: DF.to_stata(path) check(assert_type(read_stata(path), pd.DataFrame), pd.DataFrame) -def test_read_stata_iterator(): +def test_read_stata_iterator() -> None: with ensure_clean() as path: str_path = str(path) DF.to_stata(str_path) @@ -204,7 +204,7 @@ def _true_if_first_param_is_head(t: tuple[str, int]) -> bool: return t[0] == "head" -def test_clipboard(): +def test_clipboard() -> None: try: DF.to_clipboard() except errors.PyperclipException: @@ -278,7 +278,7 @@ def test_clipboard(): pd.read_clipboard(usecols="abcd") # type: ignore[call-overload] # pyright: ignore[reportArgumentType] -def test_clipboard_iterator(): +def test_clipboard_iterator() -> None: try: DF.to_clipboard() except errors.PyperclipException: @@ -346,7 +346,7 @@ def test_sas_xport() -> None: @pytest.mark.skipif(NUMPY20, reason="numpy 2.0 not compatible with Pytables") -def test_hdf(): +def test_hdf() -> None: with ensure_clean() as path: check(assert_type(DF.to_hdf(path, key="df"), None), type(None)) check(assert_type(read_hdf(path), DataFrame | Series), DataFrame) @@ -421,14 +421,14 @@ def test_hdf_context_manager() -> None: @pytest.mark.skipif(NUMPY20, reason="numpy 2.0 not compatible with Pytables") -def test_hdf_series(): +def test_hdf_series() -> None: s = DF["a"] with ensure_clean() as path: check(assert_type(s.to_hdf(path, key="s"), None), type(None)) check(assert_type(read_hdf(path, "s"), DataFrame | Series), Series) -def test_spss(): +def test_spss() -> None: path = Path(CWD, "data", "labelled-num.sav") check( assert_type(read_spss(path, convert_categoricals=True), DataFrame), @@ -440,7 +440,7 @@ def test_spss(): ) -def test_json(): +def test_json() -> None: with ensure_clean() as path: check(assert_type(DF.to_json(path), None), type(None)) check(assert_type(read_json(path), DataFrame), DataFrame) @@ -450,7 +450,7 @@ def test_json(): check(assert_type(read_json(bin_json), DataFrame), DataFrame) -def test_json_dataframe_bytes(): +def test_json_dataframe_bytes() -> None: """Test DataFrame.to_json with bytesIO buffer.""" buffer = io.BytesIO() df = pd.DataFrame() @@ -458,7 +458,7 @@ def test_json_dataframe_bytes(): check(assert_type(df.to_json(buffer), None), type(None)) -def test_json_series_bytes(): +def test_json_series_bytes() -> None: """Test Series.to_json with bytesIO buffer.""" buffer = io.BytesIO() sr = pd.Series() @@ -466,7 +466,7 @@ def test_json_series_bytes(): check(assert_type(sr.to_json(buffer), None), type(None)) -def test_json_series(): +def test_json_series() -> None: s = DF["a"] with ensure_clean() as path: check(assert_type(s.to_json(path), None), type(None)) @@ -517,7 +517,7 @@ def test_json_series(): ) -def test_json_chunk(): +def test_json_chunk() -> None: with ensure_clean() as path: check(assert_type(DF.to_json(path), None), type(None)) json_reader = read_json(path, chunksize=1, lines=True) @@ -527,14 +527,14 @@ def test_json_chunk(): check(assert_type(DF.to_json(), str), str) -def test_parquet(): +def test_parquet() -> None: with ensure_clean() as path: check(assert_type(DF.to_parquet(path), None), type(None)) check(assert_type(DF.to_parquet(), bytes), bytes) check(assert_type(read_parquet(path), DataFrame), DataFrame) -def test_parquet_options(): +def test_parquet_options() -> None: with ensure_clean(".parquet") as path: check( assert_type(DF.to_parquet(path, compression=None, index=True), None), @@ -547,7 +547,7 @@ def test_parquet_options(): check(assert_type(read_parquet(path, filters=sel), DataFrame), DataFrame) -def test_feather(): +def test_feather() -> None: with ensure_clean() as path: check(assert_type(DF.to_feather(path), None), type(None)) check(assert_type(read_feather(path), DataFrame), DataFrame) @@ -558,7 +558,7 @@ def test_feather(): check(assert_type(read_feather(bio), DataFrame), DataFrame) -def test_read_csv(): +def test_read_csv() -> None: with ensure_clean() as path: check(assert_type(DF.to_csv(path), None), type(None)) check(assert_type(read_csv(path), DataFrame), DataFrame) @@ -580,7 +580,7 @@ def cols(x: str) -> bool: pd.read_csv(path, usecols=cols) -def test_read_csv_iterator(): +def test_read_csv_iterator() -> None: with ensure_clean() as path: check(assert_type(DF.to_csv(path), None), type(None)) tfr = read_csv(path, iterator=True) @@ -782,7 +782,7 @@ def cols2(x: set[float]) -> bool: ) -def test_read_table(): +def test_read_table() -> None: with ensure_clean() as path: check(assert_type(DF.to_csv(path, sep="\t"), None), type(None)) check(assert_type(read_table(path), DataFrame), DataFrame) @@ -889,7 +889,7 @@ def test_read_table(): pd.read_table(path, usecols="abcd") # type: ignore[call-overload] # pyright: ignore[reportArgumentType] -def test_read_table_iterator(): +def test_read_table_iterator() -> None: with ensure_clean() as path: check(assert_type(DF.to_csv(path, sep="\t"), None), type(None)) tfr = read_table(path, iterator=True) @@ -900,7 +900,7 @@ def test_read_table_iterator(): tfr2.close() -def test_types_read_table(): +def test_types_read_table() -> None: df = pd.DataFrame(data={"col1": [1, 2], "col2": [3, 4]}) with ensure_clean() as path: @@ -911,7 +911,7 @@ def test_types_read_table(): ) -def test_btest_read_fwf(): +def test_btest_read_fwf() -> None: with ensure_clean() as path: DF.to_string(path, index=False) check(assert_type(read_fwf(path), DataFrame), DataFrame) @@ -934,7 +934,7 @@ def test_btest_read_fwf(): check(assert_type(fwf_iterator2, TextFileReader), TextFileReader) -def test_text_file_reader(): +def test_text_file_reader() -> None: with ensure_clean() as path: DF.to_string(path, index=False) tfr = TextFileReader(path, engine="python") @@ -950,7 +950,7 @@ def test_text_file_reader(): check(df_iter, DataFrame) -def test_to_csv_series(): +def test_to_csv_series() -> None: s = DF.iloc[:, 0] check(assert_type(s.to_csv(), str), str) with ensure_clean() as path: @@ -1103,7 +1103,7 @@ def test_read_excel_io_types() -> None: check(assert_type(pd.read_excel(as_file), pd.DataFrame), pd.DataFrame) -def test_read_excel_basic(): +def test_read_excel_basic() -> None: with ensure_clean(".xlsx") as path: check(assert_type(DF.to_excel(path), None), type(None)) check(assert_type(read_excel(path), DataFrame), DataFrame) @@ -1111,7 +1111,7 @@ def test_read_excel_basic(): check(assert_type(read_excel(path, sheet_name=0), DataFrame), DataFrame) -def test_read_excel_list(): +def test_read_excel_list() -> None: with ensure_clean(".xlsx") as path: check(assert_type(DF.to_excel(path), None), type(None)) check( @@ -1127,7 +1127,7 @@ def test_read_excel_list(): ) -def test_read_excel_dtypes(): +def test_read_excel_dtypes() -> None: # GH 440 df = pd.DataFrame({"a": [1, 2, 3], "b": ["x", "y", "z"], "c": [10.0, 20.0, 30.3]}) with ensure_clean(".xlsx") as path: @@ -1136,7 +1136,7 @@ def test_read_excel_dtypes(): check(assert_type(read_excel(path, dtype=dtypes), pd.DataFrame), pd.DataFrame) -def test_excel_reader(): +def test_excel_reader() -> None: with ensure_clean(".xlsx") as path: check(assert_type(DF.to_excel(path), None), type(None)) with pd.ExcelFile(path, engine="calamine") as ef: @@ -1152,7 +1152,7 @@ def test_excel_reader(): check(assert_type(pd.read_excel(ef), pd.DataFrame), pd.DataFrame) -def test_excel_writer(): +def test_excel_writer() -> None: with ensure_clean(".xlsx") as path: with pd.ExcelWriter(path) as ew: check(assert_type(ew, pd.ExcelWriter), pd.ExcelWriter) @@ -1171,7 +1171,7 @@ def test_excel_writer(): check(assert_type(ef.close(), None), type(None)) -def test_excel_writer_io(): +def test_excel_writer_io() -> None: buffer = io.BytesIO() with pd.ExcelWriter(buffer) as writer: DF.to_excel(writer, sheet_name="A") @@ -1181,7 +1181,7 @@ def test_excel_writer_io(): check(assert_type(read_excel(ef, sheet_name="A"), DataFrame), DataFrame) -def test_excel_writer_engine(): +def test_excel_writer_engine() -> None: with ensure_clean(".xlsx") as path: with pd.ExcelWriter(path, engine="auto") as ew: check(assert_type(ew, pd.ExcelWriter), pd.ExcelWriter) @@ -1215,7 +1215,7 @@ def test_excel_writer_engine(): ) -def test_excel_writer_append_mode(): +def test_excel_writer_append_mode() -> None: with ensure_clean(".xlsx") as path: with pd.ExcelWriter(path, mode="w") as ew: DF.to_excel(ew, sheet_name="A") @@ -1223,7 +1223,7 @@ def test_excel_writer_append_mode(): DF.to_excel(ew, sheet_name="B") -def test_to_string(): +def test_to_string() -> None: check(assert_type(DF.to_string(), str), str) with ensure_clean() as path: check(assert_type(DF.to_string(path), None), type(None)) @@ -1234,7 +1234,7 @@ def test_to_string(): check(assert_type(DF.to_string(sio), None), type(None)) -def test_read_sql(): +def test_read_sql() -> None: with ensure_clean() as path: con = sqlite3.connect(path) check(assert_type(DF.to_sql("test", con=con), int | None), int) @@ -1244,7 +1244,7 @@ def test_read_sql(): con.close() -def test_read_sql_via_sqlalchemy_connection(): +def test_read_sql_via_sqlalchemy_connection() -> None: with ensure_clean() as path: db_uri = "sqlite:///" + path engine = sqlalchemy.create_engine(db_uri) @@ -1258,7 +1258,7 @@ def test_read_sql_via_sqlalchemy_connection(): engine.dispose() -def test_read_sql_via_sqlalchemy_engine(): +def test_read_sql_via_sqlalchemy_engine() -> None: with ensure_clean() as path: db_uri = "sqlite:///" + path engine = sqlalchemy.create_engine(db_uri) @@ -1271,7 +1271,7 @@ def test_read_sql_via_sqlalchemy_engine(): engine.dispose() -def test_read_sql_via_sqlalchemy_engine_with_params(): +def test_read_sql_via_sqlalchemy_engine_with_params() -> None: with ensure_clean() as path: db_uri = "sqlite:///" + path engine = sqlalchemy.create_engine(db_uri) @@ -1291,7 +1291,7 @@ def test_read_sql_via_sqlalchemy_engine_with_params(): engine.dispose() -def test_read_sql_generator(): +def test_read_sql_generator() -> None: with ensure_clean() as path: con = sqlite3.connect(path) check(assert_type(DF.to_sql("test", con=con), int | None), int) @@ -1306,7 +1306,7 @@ def test_read_sql_generator(): con.close() -def test_read_sql_table(): +def test_read_sql_table() -> None: if TYPE_CHECKING: # sqlite3 doesn't support read_table, which is required for this function # Could only run in pytest if SQLAlchemy was installed @@ -1321,7 +1321,7 @@ def test_read_sql_table(): con.close() -def test_read_sql_query(): +def test_read_sql_query() -> None: with ensure_clean() as path: con = sqlite3.connect(path) check(assert_type(DF.to_sql("test", con=con), int | None), int) @@ -1335,7 +1335,7 @@ def test_read_sql_query(): con.close() -def test_read_sql_query_generator(): +def test_read_sql_query_generator() -> None: with ensure_clean() as path: con = sqlite3.connect(path) check(assert_type(DF.to_sql("test", con=con), int | None), int) @@ -1350,7 +1350,7 @@ def test_read_sql_query_generator(): con.close() -def test_read_sql_query_via_sqlalchemy_engine_with_params(): +def test_read_sql_query_via_sqlalchemy_engine_with_params() -> None: with ensure_clean() as path: db_uri = "sqlite:///" + path engine = sqlalchemy.create_engine(db_uri) @@ -1373,7 +1373,7 @@ def test_read_sql_query_via_sqlalchemy_engine_with_params(): @pytest.mark.skip( reason="Only works in Postgres (and MySQL, but with different query syntax)" ) -def test_read_sql_query_via_sqlalchemy_engine_with_tuple_valued_params(): +def test_read_sql_query_via_sqlalchemy_engine_with_tuple_valued_params() -> None: with ensure_clean(): db_uri = "postgresql+psycopg2://postgres@localhost:5432/postgres" engine = sqlalchemy.create_engine(db_uri) @@ -1403,7 +1403,7 @@ def test_read_sql_query_via_sqlalchemy_engine_with_tuple_valued_params(): engine.dispose() -def test_read_html(): +def test_read_html() -> None: check(assert_type(DF.to_html(), str), str) with ensure_clean() as path: check(assert_type(DF.to_html(path), None), type(None)) @@ -1416,7 +1416,7 @@ def test_read_html(): ) -def test_csv_quoting(): +def test_csv_quoting() -> None: with ensure_clean() as path: check(assert_type(DF.to_csv(path, quoting=csv.QUOTE_ALL), None), type(None)) check(assert_type(DF.to_csv(path, quoting=csv.QUOTE_NONE), None), type(None)) diff --git a/tests/test_pandas.py b/tests/test_pandas.py index f03705ed6..0d9917271 100644 --- a/tests/test_pandas.py +++ b/tests/test_pandas.py @@ -688,7 +688,7 @@ def test_arrow_dtype() -> None: ) -def test_hashing(): +def test_hashing() -> None: a = np.array([1, 2, 3]) check(assert_type(pdutil.hash_array(a), npt.NDArray[np.uint64]), np.ndarray) check( @@ -716,7 +716,7 @@ def test_hashing(): ) -def test_eval(): +def test_eval() -> None: df = pd.DataFrame({"animal": ["dog", "pig"], "age": [10, 20]}) check( assert_type( @@ -821,7 +821,7 @@ def test_to_numeric_array_series() -> None: ) -def test_wide_to_long(): +def test_wide_to_long() -> None: df = pd.DataFrame( { "A1970": {0: "a", 1: "b", 2: "c"}, @@ -845,7 +845,7 @@ def test_wide_to_long(): ) -def test_melt(): +def test_melt() -> None: df = pd.DataFrame( { "A": {0: "a", 1: "b", 2: "c"}, diff --git a/tests/test_plotting.py b/tests/test_plotting.py index c14938e1f..69d5db3b2 100644 --- a/tests/test_plotting.py +++ b/tests/test_plotting.py @@ -284,7 +284,7 @@ def test_table(close_figures) -> None: check(assert_type(pd.plotting.table(ax, df), Table), Table) -def test_plot_line(): +def test_plot_line() -> None: check(assert_type(IRIS_DF.plot(), Axes), Axes) check(assert_type(IRIS_DF.plot.line(), Axes), Axes) check(assert_type(IRIS_DF.plot(kind="line"), Axes), Axes) @@ -511,7 +511,7 @@ def test_plot_scatter(close_figures) -> None: ) -def test_plot_keywords(close_figures): +def test_plot_keywords(close_figures) -> None: _, ax = plt.subplots(1, 1) df = IRIS_DF.iloc[:, :3].abs() check( @@ -595,7 +595,7 @@ def test_plot_subplot_changes_150() -> None: ) -def test_grouped_dataframe_boxplot(close_figures): +def test_grouped_dataframe_boxplot(close_figures) -> None: tuples = [t for t in itertools.product(range(10), range(2))] index = pd.MultiIndex.from_tuples(tuples, names=["lvl0", "lvl1"]) df = pd.DataFrame( @@ -624,7 +624,7 @@ def test_grouped_dataframe_boxplot(close_figures): ) -def test_grouped_dataframe_boxplot_single(close_figures): +def test_grouped_dataframe_boxplot_single(close_figures) -> None: """ Test with pandas 2.2.3 separated to make it pass. @@ -672,7 +672,7 @@ def test_grouped_dataframe_boxplot_single(close_figures): check(assert_type(grouped.boxplot(subplots=bool(0.5)), Axes | Series), Series) -def test_grouped_dataframe_hist(close_figures): +def test_grouped_dataframe_hist(close_figures) -> None: df = IRIS_DF.iloc[:50] grouped = df.groupby("Name") check(assert_type(grouped.hist(), Series), Series) @@ -696,7 +696,7 @@ def test_grouped_dataframe_hist(close_figures): ) -def test_grouped_dataframe_hist_str(close_figures): +def test_grouped_dataframe_hist_str(close_figures) -> None: df = IRIS_DF.iloc[:50] grouped = df.groupby("Name") check(assert_type(grouped.hist(), Series), Series) @@ -720,7 +720,7 @@ def test_grouped_dataframe_hist_str(close_figures): ) -def test_grouped_series_hist(close_figures): +def test_grouped_series_hist(close_figures) -> None: multi_index = pd.MultiIndex.from_tuples([(0, 0), (0, 1), (1, 0)], names=["a", "b"]) s = pd.Series([0, 1, 2], index=multi_index, dtype=int) grouped = s.groupby(level=0) diff --git a/tests/test_string_accessors.py b/tests/test_string_accessors.py index ac83e6e3a..7ab9e769f 100644 --- a/tests/test_string_accessors.py +++ b/tests/test_string_accessors.py @@ -31,7 +31,7 @@ def test_string_accessors_type_preserving_index() -> None: check(assert_type(idx_bytes.str.slice(0, 4, 2), "pd.Index[bytes]"), pd.Index, bytes) -def test_string_accessors_boolean_series(): +def test_string_accessors_boolean_series() -> None: s = pd.Series(DATA) _check = functools.partial(check, klass=pd.Series, dtype=np.bool_) _check(assert_type(s.str.startswith("a"), "pd.Series[bool]")) @@ -69,7 +69,7 @@ def test_string_accessors_boolean_series(): _check(assert_type(s.str.match(re.compile(r"pp")), "pd.Series[bool]")) -def test_string_accessors_boolean_index(): +def test_string_accessors_boolean_index() -> None: idx = pd.Index(DATA) _check = functools.partial(check, klass=np_1darray[np.bool]) _check(assert_type(idx.str.startswith("a"), np_1darray[np.bool])) @@ -109,7 +109,7 @@ def test_string_accessors_boolean_index(): _check(assert_type(idx.str.match(re.compile(r"pp")), np_1darray[np.bool])) -def test_string_accessors_integer_series(): +def test_string_accessors_integer_series() -> None: s = pd.Series(DATA) _check = functools.partial(check, klass=pd.Series, dtype=np.integer) _check(assert_type(s.str.find("p"), "pd.Series[int]")) @@ -124,7 +124,7 @@ def test_string_accessors_integer_series(): s.str.find(re.compile(r"p")) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] -def test_string_accessors_integer_index(): +def test_string_accessors_integer_index() -> None: idx = pd.Index(DATA) _check = functools.partial(check, klass=pd.Index, dtype=np.integer) _check(assert_type(idx.str.find("p"), "pd.Index[int]")) @@ -139,7 +139,7 @@ def test_string_accessors_integer_index(): idx.str.find(re.compile(r"p")) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] -def test_string_accessors_string_series(): +def test_string_accessors_string_series() -> None: s = pd.Series(DATA) _check = functools.partial(check, klass=pd.Series, dtype=str) _check(assert_type(s.str.capitalize(), "pd.Series[str]")) @@ -197,7 +197,7 @@ def test_string_accessors_string_series(): s.str.wrap(80, False) # type: ignore[misc] # pyright: ignore[reportCallIssue] -def test_string_accessors_string_index(): +def test_string_accessors_string_index() -> None: idx = pd.Index(DATA) _check = functools.partial(check, klass=pd.Index, dtype=str) _check(assert_type(idx.str.capitalize(), "pd.Index[str]")) @@ -255,17 +255,17 @@ def test_string_accessors_string_index(): idx.str.wrap(80, False) # type: ignore[misc] # pyright: ignore[reportCallIssue] -def test_string_accessors_bytes_series(): +def test_string_accessors_bytes_series() -> None: s = pd.Series(["a1", "b2", "c3"]) check(assert_type(s.str.encode("latin-1"), "pd.Series[bytes]"), pd.Series, bytes) -def test_string_accessors_bytes_index(): +def test_string_accessors_bytes_index() -> None: s = pd.Index(["a1", "b2", "c3"]) check(assert_type(s.str.encode("latin-1"), "pd.Index[bytes]"), pd.Index, bytes) -def test_string_accessors_list_series(): +def test_string_accessors_list_series() -> None: s = pd.Series(DATA) _check = functools.partial(check, klass=pd.Series, dtype=list) _check(assert_type(s.str.findall("pp"), "pd.Series[list[str]]")) @@ -285,7 +285,7 @@ def test_string_accessors_list_series(): ) -def test_string_accessors_list_index(): +def test_string_accessors_list_index() -> None: idx = pd.Index(DATA) _check = functools.partial(check, klass=pd.Index, dtype=list) _check(assert_type(idx.str.findall("pp"), "pd.Index[list[str]]")) @@ -305,7 +305,7 @@ def test_string_accessors_list_index(): ) -def test_string_accessors_expanding_series(): +def test_string_accessors_expanding_series() -> None: s = pd.Series(["a1", "b2", "c3"]) _check = functools.partial(check, klass=pd.DataFrame) _check(assert_type(s.str.extract(r"([ab])?(\d)"), pd.DataFrame)) @@ -319,7 +319,7 @@ def test_string_accessors_expanding_series(): _check(assert_type(s.str.split("a", expand=True), pd.DataFrame)) -def test_string_accessors_expanding_index(): +def test_string_accessors_expanding_index() -> None: idx = pd.Index(["a1", "b2", "c3"]) _check = functools.partial(check, klass=pd.MultiIndex) _check(assert_type(idx.str.get_dummies(), pd.MultiIndex)) @@ -341,7 +341,7 @@ def test_string_accessors_expanding_index(): ) -def test_series_overloads_partition(): +def test_series_overloads_partition() -> None: s = pd.Series( [ "ap;pl;ep", @@ -380,7 +380,7 @@ def test_series_overloads_partition(): check(assert_type(s.str.rpartition(expand=False), pd.Series), pd.Series, object) -def test_index_overloads_partition(): +def test_index_overloads_partition() -> None: idx = pd.Index( [ "ap;pl;ep", @@ -415,7 +415,7 @@ def test_index_overloads_partition(): ) -def test_series_overloads_cat(): +def test_series_overloads_cat() -> None: s = pd.Series(DATA) check(assert_type(s.str.cat(sep=";"), str), str) check(assert_type(s.str.cat(None, sep=";"), str), str) @@ -445,7 +445,7 @@ def test_series_overloads_cat(): ) -def test_index_overloads_cat(): +def test_index_overloads_cat() -> None: idx = pd.Index(DATA) check(assert_type(idx.str.cat(sep=";"), str), str) check(assert_type(idx.str.cat(None, sep=";"), str), str) @@ -479,7 +479,7 @@ def test_index_overloads_cat(): ) -def test_series_overloads_extract(): +def test_series_overloads_extract() -> None: s = pd.Series(DATA) check(assert_type(s.str.extract(r"[ab](\d)"), pd.DataFrame), pd.DataFrame) check( @@ -497,7 +497,7 @@ def test_series_overloads_extract(): ) -def test_index_overloads_extract(): +def test_index_overloads_extract() -> None: idx = pd.Index(DATA) check(assert_type(idx.str.extract(r"[ab](\d)"), pd.DataFrame), pd.DataFrame) check( diff --git a/tests/test_styler.py b/tests/test_styler.py index 49cb3f845..922375051 100644 --- a/tests/test_styler.py +++ b/tests/test_styler.py @@ -44,7 +44,7 @@ def reset_style(): DF.style.clear() -def test_apply(): +def test_apply() -> None: def f(s: Series) -> Series: return s @@ -188,7 +188,7 @@ def test_set() -> None: check(assert_type(DF.style.set_uuid("r4nd0mc44r4c73r5"), Styler), Styler) -def test_styler_templates(): +def test_styler_templates() -> None: check(assert_type(DF.style.template_html, Template), Template) check(assert_type(DF.style.template_html_style, Template), Template) check(assert_type(DF.style.template_html_table, Template), Template) diff --git a/tests/test_testing.py b/tests/test_testing.py index 2ca593af7..afb127ae5 100644 --- a/tests/test_testing.py +++ b/tests/test_testing.py @@ -51,14 +51,14 @@ def test_types_assert_series_equal() -> None: assert_series_equal(s1, s2, check_index=False) -def test_assert_frame_equal(): +def test_assert_frame_equal() -> None: df1 = pd.DataFrame({"x": [1, 2, 3]}) df2 = pd.DataFrame({"x": [1, 2, 3]}) # GH 56 assert_frame_equal(df1, df2, check_index_type=False) -def test_ensure_clean(): +def test_ensure_clean() -> None: with ensure_clean() as path: check(assert_type(path, str), str) pd.DataFrame({"x": [1, 2, 3]}).to_csv(path) diff --git a/tests/test_timefuncs.py b/tests/test_timefuncs.py index e126b8ada..a654015fb 100644 --- a/tests/test_timefuncs.py +++ b/tests/test_timefuncs.py @@ -1717,7 +1717,7 @@ def test_timedeltaseries_add_timestampseries() -> None: check(assert_type(plus, "pd.Series[pd.Timestamp]"), pd.Series, pd.Timestamp) -def test_timestamp_strptime_fails(): +def test_timestamp_strptime_fails() -> None: if TYPE_CHECKING_INVALID_USAGE: assert_never( pd.Timestamp.strptime( @@ -1727,7 +1727,7 @@ def test_timestamp_strptime_fails(): ) -def test_weekofmonth_init(): +def test_weekofmonth_init() -> None: # GH 629 check( assert_type( @@ -1774,7 +1774,7 @@ def test_dateoffset_weekday() -> None: ) -def test_date_range_unit(): +def test_date_range_unit() -> None: check( assert_type(pd.date_range("1/1/2022", "2/1/2022", unit="s"), pd.DatetimeIndex), pd.DatetimeIndex, diff --git a/tests/test_utility.py b/tests/test_utility.py index 0b081545a..7075981be 100644 --- a/tests/test_utility.py +++ b/tests/test_utility.py @@ -4,13 +4,13 @@ from tests import check -def test_show_version(): +def test_show_version() -> None: """Test show_versions method types with split case for pandas and python versions.""" check(assert_type(pd.show_versions(True), None), type(None)) check(assert_type(pd.show_versions(False), None), type(None)) -def test_dummies(): +def test_dummies() -> None: df = pd.DataFrame( pd.Series(["a", "b", "a", "b", "c", "a", "a"], dtype="category"), columns=["A"] ) @@ -28,7 +28,7 @@ def test_dummies(): ) -def test_get_dummies_args(): +def test_get_dummies_args() -> None: df = pd.DataFrame( { "A": pd.Series(["a", "b", "a", "b", "c", "a", "a"], dtype="category"), @@ -59,7 +59,7 @@ def test_get_dummies_args(): ) -def test_from_dummies_args(): +def test_from_dummies_args() -> None: df = pd.DataFrame( { "A": pd.Series(["a", "b", "a", "b", "c", "a", "a"], dtype="category"), From 5511ced6e2e599f3fbda4c62bf2304d95091acd9 Mon Sep 17 00:00:00 2001 From: cmp0xff Date: Sat, 4 Oct 2025 19:09:03 +0200 Subject: [PATCH 4/4] refactor: return None by ruff --- scripts/_job.py | 2 +- scripts/test/__init__.py | 2 +- scripts/test/run.py | 38 ++++++++++++++++++------------------- tests/series/test_series.py | 2 +- tests/test_api_types.py | 2 +- tests/test_api_typing.py | 32 +++++++++++++++---------------- tests/test_plotting.py | 4 ++-- tests/test_styler.py | 10 ++-------- 8 files changed, 43 insertions(+), 49 deletions(-) diff --git a/scripts/_job.py b/scripts/_job.py index 3a222bb03..7a5c175b9 100644 --- a/scripts/_job.py +++ b/scripts/_job.py @@ -14,7 +14,7 @@ class Step: rollback: Callable[[], None] | None = None -def __rollback_job(steps: deque[Step]): +def __rollback_job(steps: deque[Step]) -> None: """ Responsible to run rollback of steps. """ diff --git a/scripts/test/__init__.py b/scripts/test/__init__.py index 6363a3d83..57366bdba 100644 --- a/scripts/test/__init__.py +++ b/scripts/test/__init__.py @@ -25,7 +25,7 @@ def test( src: bool = False, dist: bool = False, type_checker: Literal["", "mypy", "pyright"] = "", -): +) -> None: steps = [] if src: steps.extend(_SRC_STEPS) diff --git a/scripts/test/run.py b/scripts/test/run.py index c6ecde1e2..a876d5bcc 100644 --- a/scripts/test/run.py +++ b/scripts/test/run.py @@ -5,32 +5,32 @@ import sys -def mypy_src(): +def mypy_src() -> None: cmd = ["mypy", "pandas-stubs", "tests", "--no-incremental"] subprocess.run(cmd, check=True) -def pyright_src(): +def pyright_src() -> None: cmd = ["pyright"] subprocess.run(cmd, check=True) -def pyright_src_strict(): +def pyright_src_strict() -> None: cmd = ["pyright", "--project", "pyrightconfig-strict.json"] subprocess.run(cmd, check=True) -def pytest(): +def pytest() -> None: cmd = ["pytest", "--cache-clear"] subprocess.run(cmd, check=True) -def style(): +def style() -> None: cmd = ["pre-commit", "run", "--all-files", "--verbose"] subprocess.run(cmd, check=True) -def stubtest(allowlist: str = "", check_missing: bool = False): +def stubtest(allowlist: str = "", check_missing: bool = False) -> None: cmd = [ sys.executable, "-m", @@ -47,47 +47,47 @@ def stubtest(allowlist: str = "", check_missing: bool = False): subprocess.run(cmd, check=True) -def build_dist(): +def build_dist() -> None: cmd = ["poetry", "build", "-f", "wheel"] subprocess.run(cmd, check=True) -def install_dist(): +def install_dist() -> None: path = sorted(Path("dist/").glob("pandas_stubs-*.whl"))[-1] cmd = [sys.executable, "-m", "pip", "install", "--force-reinstall", str(path)] subprocess.run(cmd, check=True) -def rename_src(): +def rename_src() -> None: if Path(r"pandas-stubs").exists(): Path(r"pandas-stubs").rename("_pandas-stubs") else: raise FileNotFoundError("'pandas-stubs' folder does not exists.") -def mypy_dist(): +def mypy_dist() -> None: cmd = ["mypy", "tests", "--no-incremental"] subprocess.run(cmd, check=True) -def pyright_dist(): +def pyright_dist() -> None: cmd = ["pyright", "tests"] subprocess.run(cmd, check=True) -def uninstall_dist(): +def uninstall_dist() -> None: cmd = [sys.executable, "-m", "pip", "uninstall", "-y", "pandas-stubs"] subprocess.run(cmd, check=True) -def restore_src(): +def restore_src() -> None: if Path(r"_pandas-stubs").exists(): Path(r"_pandas-stubs").rename("pandas-stubs") else: raise FileNotFoundError("'_pandas-stubs' folder does not exists.") -def nightly_pandas(): +def nightly_pandas() -> None: cmd = [ sys.executable, "-m", @@ -110,13 +110,13 @@ def _get_version_from_pyproject(program: str) -> str: return version_line.split('"')[1] -def released_pandas(): +def released_pandas() -> None: version = _get_version_from_pyproject("pandas") cmd = [sys.executable, "-m", "pip", "install", f"pandas=={version}"] subprocess.run(cmd, check=True) -def nightly_mypy(): +def nightly_mypy() -> None: cmd = [ sys.executable, "-m", @@ -138,7 +138,7 @@ def nightly_mypy(): ) -def released_mypy(): +def released_mypy() -> None: version = _get_version_from_pyproject("mypy") cmd = [sys.executable, "-m", "pip", "install", f"mypy=={version}"] subprocess.run(cmd, check=True) @@ -152,7 +152,7 @@ def released_mypy(): ) -def ty(): +def ty() -> None: cmd = [ "ty", "check", @@ -163,6 +163,6 @@ def ty(): subprocess.run(cmd, check=True) -def pyrefly(): +def pyrefly() -> None: cmd = ["pyrefly", "check", "pandas-stubs"] subprocess.run(cmd, check=True) diff --git a/tests/series/test_series.py b/tests/series/test_series.py index 5bc6a26e2..7345dd275 100644 --- a/tests/series/test_series.py +++ b/tests/series/test_series.py @@ -3549,7 +3549,7 @@ def test_diff() -> None: # str -> TypeError: unsupported operand type(s) for -: 'str' and 'str' pd.Series(["a", "b"]).diff() # type: ignore[misc] # pyright: ignore[reportAttributeAccessIssue] - def _diff_invalid0(): # pyright: ignore[reportUnusedFunction] + def _diff_invalid0() -> None: # pyright: ignore[reportUnusedFunction] # interval -> TypeError: IntervalArray has no 'diff' method. Convert to a suitable dtype prior to calling 'diff'. assert_type(pd.Series([pd.Interval(0, 2), pd.Interval(1, 4)]).diff(), Never) diff --git a/tests/test_api_types.py b/tests/test_api_types.py index b0d6352ad..b4d6167ff 100644 --- a/tests/test_api_types.py +++ b/tests/test_api_types.py @@ -373,7 +373,7 @@ def test_union_categoricals() -> None: def test_check_extension_dtypes() -> None: # GH 315 - def check_ext_dtype(etype: type[ExtensionDtype]): + def check_ext_dtype(etype: type[ExtensionDtype]) -> None: assert issubclass(etype, ExtensionDtype) check_ext_dtype(pd.Int64Dtype) diff --git a/tests/test_api_typing.py b/tests/test_api_typing.py index e9d014e57..5b01be922 100644 --- a/tests/test_api_typing.py +++ b/tests/test_api_typing.py @@ -46,7 +46,7 @@ def test_dataframegroupby() -> None: df = pd.DataFrame({"a": [1, 2, 3]}) group = df.groupby("a") - def f1(gb: DataFrameGroupBy): + def f1(gb: DataFrameGroupBy) -> None: check(gb, DataFrameGroupBy) f1(group) @@ -55,7 +55,7 @@ def f1(gb: DataFrameGroupBy): def test_seriesgroupby() -> None: sr = pd.Series([1, 2, 3], index=pd.Index(["a", "b", "a"])) - def f1(gb: SeriesGroupBy): + def f1(gb: SeriesGroupBy) -> None: check(gb, SeriesGroupBy) f1(sr.groupby(level=0)) @@ -68,7 +68,7 @@ def tests_datetimeindexersamplergroupby() -> None: ) gb_df = df.groupby("col2") - def f1(gb: ResamplerGroupBy): + def f1(gb: ResamplerGroupBy) -> None: check(gb, DatetimeIndexResamplerGroupby) f1(gb_df.resample("ME")) @@ -81,7 +81,7 @@ def test_timedeltaindexresamplergroupby() -> None: ) gb_df = df.groupby("col2") - def f1(gb: ResamplerGroupBy): + def f1(gb: ResamplerGroupBy) -> None: check(gb, TimedeltaIndexResamplerGroupby) f1(gb_df.resample("1D")) @@ -92,7 +92,7 @@ def test_periodindexresamplergroupby() -> None: idx = pd.period_range("2020-01-28 09:00", periods=4, freq="D") df = pd.DataFrame(data=4 * [range(2)], index=idx, columns=["a", "b"]) - def f1(gb: ResamplerGroupBy): + def f1(gb: ResamplerGroupBy) -> None: check(gb, PeriodIndexResamplerGroupby) f1(df.groupby("a").resample("3min")) @@ -113,7 +113,7 @@ def test_nattype() -> None: def test_expanding() -> None: df = pd.DataFrame({"B": [0, 1, 2, np.nan, 4]}) - def f1(gb: Expanding): + def f1(gb: Expanding) -> None: check(gb, Expanding) f1(df.expanding()) @@ -122,7 +122,7 @@ def f1(gb: Expanding): def test_expanding_groubpy() -> None: df = pd.DataFrame({"B": [0, 1, 2, np.nan, 4]}) - def f1(gb: ExpandingGroupby): + def f1(gb: ExpandingGroupby) -> None: check(gb, ExpandingGroupby) f1(df.groupby("B").expanding()) @@ -131,7 +131,7 @@ def f1(gb: ExpandingGroupby): def test_ewm() -> None: df = pd.DataFrame({"B": [0, 1, 2, np.nan, 4]}) - def f1(gb: ExponentialMovingWindow): + def f1(gb: ExponentialMovingWindow) -> None: check(gb, ExponentialMovingWindow) f1(df.ewm(2)) @@ -140,7 +140,7 @@ def f1(gb: ExponentialMovingWindow): def test_ewm_groubpy() -> None: df = pd.DataFrame({"B": [0, 1, 2, np.nan, 4]}) - def f1(gb: ExponentialMovingWindowGroupby): + def f1(gb: ExponentialMovingWindowGroupby) -> None: check(gb, ExponentialMovingWindowGroupby) f1(df.groupby("B").ewm(2)) @@ -149,7 +149,7 @@ def f1(gb: ExponentialMovingWindowGroupby): def test_json_reader() -> None: df = pd.DataFrame({"B": [0, 1, 2, np.nan, 4]}) - def f1(gb: JsonReader): + def f1(gb: JsonReader) -> None: check(gb, JsonReader) with ensure_clean() as path: @@ -162,7 +162,7 @@ def f1(gb: JsonReader): def test_resampler() -> None: s = pd.Series([1, 2, 3, 4, 5], index=pd.date_range("20130101", periods=5, freq="s")) - def f1(gb: Resampler): + def f1(gb: Resampler) -> None: check(gb, Resampler) f1(s.resample("3min")) @@ -171,7 +171,7 @@ def f1(gb: Resampler): def test_rolling() -> None: df = pd.DataFrame({"B": [0, 1, 2, np.nan, 4]}) - def f1(gb: Rolling): + def f1(gb: Rolling) -> None: check(gb, Rolling) f1(df.rolling(2)) @@ -180,7 +180,7 @@ def f1(gb: Rolling): def test_rolling_groupby() -> None: df = pd.DataFrame({"B": [0, 1, 2, np.nan, 4]}) - def f1(gb: RollingGroupby): + def f1(gb: RollingGroupby) -> None: check(gb, RollingGroupby) f1(df.groupby("B").rolling(2)) @@ -189,7 +189,7 @@ def f1(gb: RollingGroupby): def test_timegrouper() -> None: grouper = pd.Grouper(key="Publish date", freq="1W") - def f1(gb: TimeGrouper): + def f1(gb: TimeGrouper) -> None: check(gb, TimeGrouper) f1(grouper) @@ -198,7 +198,7 @@ def f1(gb: TimeGrouper): def test_window() -> None: ser = pd.Series([0, 1, 5, 2, 8]) - def f1(gb: Window): + def f1(gb: Window) -> None: check(gb, Window) f1(ser.rolling(2, win_type="gaussian")) @@ -213,7 +213,7 @@ def test_statereader() -> None: path, time_stamp=time_stamp, variable_labels=variable_labels, version=None ) - def f1(gb: StataReader): + def f1(gb: StataReader) -> None: check(gb, StataReader) with StataReader(path) as reader: diff --git a/tests/test_plotting.py b/tests/test_plotting.py index 69d5db3b2..38649ea50 100644 --- a/tests/test_plotting.py +++ b/tests/test_plotting.py @@ -27,12 +27,12 @@ @pytest.fixture(autouse=True) -def autouse_mpl_cleanup(mpl_cleanup): +def autouse_mpl_cleanup(mpl_cleanup) -> None: pass @pytest.fixture -def close_figures(): +def close_figures() -> None: plt.close("all") diff --git a/tests/test_styler.py b/tests/test_styler.py index 922375051..1de209a43 100644 --- a/tests/test_styler.py +++ b/tests/test_styler.py @@ -40,7 +40,7 @@ @pytest.fixture(autouse=True) -def reset_style(): +def reset_style() -> None: DF.style.clear() @@ -255,10 +255,4 @@ def color_negative(v: Scalar, /, color: str) -> str | None: df = DataFrame(np.random.randn(5, 2), columns=["A", "B"]) - check( - assert_type( - df.style.map(color_negative, color="red"), - Styler, - ), - Styler, - ) + check(assert_type(df.style.map(color_negative, color="red"), Styler), Styler)