From 57b74109c3da0c4d1e940cfda288164e970ce93b Mon Sep 17 00:00:00 2001 From: MarcoGorelli Date: Sat, 1 Jul 2023 07:05:26 +0000 Subject: [PATCH 1/4] =?UTF-8?q?=E2=AC=86=EF=B8=8F=20UPGRADE:=20Autoupdate?= =?UTF-8?q?=20pre-commit=20config?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .pre-commit-config.yaml | 6 ++--- pandas/_libs/algos.pyi | 6 ----- pandas/core/algorithms.py | 2 +- pandas/core/arrays/_mixins.py | 2 +- pandas/core/arrays/arrow/array.py | 2 +- pandas/core/arrays/base.py | 2 +- pandas/core/arrays/masked.py | 2 +- pandas/core/arrays/period.py | 2 +- pandas/core/arrays/sparse/array.py | 2 +- pandas/core/arrays/string_.py | 2 +- pandas/core/base.py | 2 +- pandas/core/dtypes/dtypes.py | 2 +- pandas/core/frame.py | 40 ++++++++++++++-------------- pandas/core/generic.py | 42 +++++++++++++++--------------- pandas/core/groupby/generic.py | 4 +-- pandas/core/indexes/base.py | 6 ++--- pandas/core/indexes/category.py | 2 +- pandas/core/indexes/datetimes.py | 6 ++--- pandas/core/indexes/interval.py | 10 +++---- pandas/core/indexes/multi.py | 2 +- pandas/core/indexes/period.py | 4 +-- pandas/core/indexes/range.py | 8 +++--- pandas/core/series.py | 24 ++++++++--------- pandas/core/tools/datetimes.py | 4 +-- pandas/io/common.py | 8 +++--- pandas/io/excel/_base.py | 12 ++++----- pandas/io/excel/_odfreader.py | 2 +- pandas/io/excel/_odswriter.py | 2 +- pandas/io/excel/_openpyxl.py | 4 +-- pandas/io/excel/_pyxlsb.py | 2 +- pandas/io/excel/_xlrd.py | 2 +- pandas/io/excel/_xlsxwriter.py | 2 +- pandas/io/feather_format.py | 4 +-- pandas/io/formats/csvs.py | 2 +- pandas/io/formats/excel.py | 2 +- pandas/io/formats/format.py | 2 +- pandas/io/formats/style.py | 2 +- pandas/io/formats/xml.py | 2 +- pandas/io/json/_json.py | 6 ++--- pandas/io/parquet.py | 14 +++++----- pandas/io/parsers/readers.py | 4 +-- pandas/io/pickle.py | 4 +-- pandas/io/sql.py | 2 +- pandas/io/stata.py | 10 +++---- pandas/io/xml.py | 2 +- pandas/plotting/_core.py | 20 +++++++------- 46 files changed, 144 insertions(+), 150 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4379220c33687..8be67546f17a4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,7 +28,7 @@ repos: types_or: [python, pyi] additional_dependencies: [black==23.3.0] - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: v0.0.270 + rev: v0.0.275 hooks: - id: ruff args: [--exit-non-zero-on-fix] @@ -40,7 +40,7 @@ repos: pass_filenames: true require_serial: false - repo: https://github.com/codespell-project/codespell - rev: v2.2.4 + rev: v2.2.5 hooks: - id: codespell types_or: [python, rst, markdown, cython, c] @@ -103,7 +103,7 @@ repos: hooks: - id: isort - repo: https://github.com/asottile/pyupgrade - rev: v3.4.0 + rev: v3.7.0 hooks: - id: pyupgrade args: [--py38-plus] diff --git a/pandas/_libs/algos.pyi b/pandas/_libs/algos.pyi index 20a805533e8cc..cd6c02f49c635 100644 --- a/pandas/_libs/algos.pyi +++ b/pandas/_libs/algos.pyi @@ -5,9 +5,6 @@ import numpy as np from pandas._typing import npt class Infinity: - """ - Provide a positive Infinity comparison method for ranking. - """ def __eq__(self, other) -> bool: ... def __ne__(self, other) -> bool: ... @@ -17,9 +14,6 @@ class Infinity: def __ge__(self, other) -> bool: ... class NegInfinity: - """ - Provide a negative Infinity comparison method for ranking. - """ def __eq__(self, other) -> bool: ... def __ne__(self, other) -> bool: ... diff --git a/pandas/core/algorithms.py b/pandas/core/algorithms.py index 9d0e2145567bf..5783842e9ddef 100644 --- a/pandas/core/algorithms.py +++ b/pandas/core/algorithms.py @@ -1322,7 +1322,7 @@ def searchsorted( arr: ArrayLike, value: NumpyValueArrayLike | ExtensionArray, side: Literal["left", "right"] = "left", - sorter: NumpySorter = None, + sorter: NumpySorter | None = None, ) -> npt.NDArray[np.intp] | np.intp: """ Find indices where elements should be inserted to maintain order. diff --git a/pandas/core/arrays/_mixins.py b/pandas/core/arrays/_mixins.py index f586de3d2bdee..d0b196eabe41c 100644 --- a/pandas/core/arrays/_mixins.py +++ b/pandas/core/arrays/_mixins.py @@ -232,7 +232,7 @@ def searchsorted( self, value: NumpyValueArrayLike | ExtensionArray, side: Literal["left", "right"] = "left", - sorter: NumpySorter = None, + sorter: NumpySorter | None = None, ) -> npt.NDArray[np.intp] | np.intp: npvalue = self._validate_setitem_value(value) return self._ndarray.searchsorted(npvalue, side=side, sorter=sorter) diff --git a/pandas/core/arrays/arrow/array.py b/pandas/core/arrays/arrow/array.py index 85a75fff25ebd..360205b0857da 100644 --- a/pandas/core/arrays/arrow/array.py +++ b/pandas/core/arrays/arrow/array.py @@ -1060,7 +1060,7 @@ def searchsorted( self, value: NumpyValueArrayLike | ExtensionArray, side: Literal["left", "right"] = "left", - sorter: NumpySorter = None, + sorter: NumpySorter | None = None, ) -> npt.NDArray[np.intp] | np.intp: if self._hasna: raise ValueError( diff --git a/pandas/core/arrays/base.py b/pandas/core/arrays/base.py index ceac8e22426d9..fe8d595572cd6 100644 --- a/pandas/core/arrays/base.py +++ b/pandas/core/arrays/base.py @@ -914,7 +914,7 @@ def searchsorted( self, value: NumpyValueArrayLike | ExtensionArray, side: Literal["left", "right"] = "left", - sorter: NumpySorter = None, + sorter: NumpySorter | None = None, ) -> npt.NDArray[np.intp] | np.intp: """ Find indices where elements should be inserted to maintain order. diff --git a/pandas/core/arrays/masked.py b/pandas/core/arrays/masked.py index 15c485cbb1499..d255d009dac1b 100644 --- a/pandas/core/arrays/masked.py +++ b/pandas/core/arrays/masked.py @@ -920,7 +920,7 @@ def searchsorted( self, value: NumpyValueArrayLike | ExtensionArray, side: Literal["left", "right"] = "left", - sorter: NumpySorter = None, + sorter: NumpySorter | None = None, ) -> npt.NDArray[np.intp] | np.intp: if self._hasna: raise ValueError( diff --git a/pandas/core/arrays/period.py b/pandas/core/arrays/period.py index c9c2d258a9a16..ff221ec3be006 100644 --- a/pandas/core/arrays/period.py +++ b/pandas/core/arrays/period.py @@ -780,7 +780,7 @@ def searchsorted( self, value: NumpyValueArrayLike | ExtensionArray, side: Literal["left", "right"] = "left", - sorter: NumpySorter = None, + sorter: NumpySorter | None = None, ) -> npt.NDArray[np.intp] | np.intp: npvalue = self._validate_setitem_value(value).view("M8[ns]") diff --git a/pandas/core/arrays/sparse/array.py b/pandas/core/arrays/sparse/array.py index aba6811c5eeb7..d342cc2f0d9f1 100644 --- a/pandas/core/arrays/sparse/array.py +++ b/pandas/core/arrays/sparse/array.py @@ -1134,7 +1134,7 @@ def searchsorted( self, v: ArrayLike | object, side: Literal["left", "right"] = "left", - sorter: NumpySorter = None, + sorter: NumpySorter | None = None, ) -> npt.NDArray[np.intp] | np.intp: msg = "searchsorted requires high memory usage." warnings.warn(msg, PerformanceWarning, stacklevel=find_stack_level()) diff --git a/pandas/core/arrays/string_.py b/pandas/core/arrays/string_.py index a6579879cab96..2640cbd7f6ba1 100644 --- a/pandas/core/arrays/string_.py +++ b/pandas/core/arrays/string_.py @@ -513,7 +513,7 @@ def searchsorted( self, value: NumpyValueArrayLike | ExtensionArray, side: Literal["left", "right"] = "left", - sorter: NumpySorter = None, + sorter: NumpySorter | None = None, ) -> npt.NDArray[np.intp] | np.intp: if self._hasna: raise ValueError( diff --git a/pandas/core/base.py b/pandas/core/base.py index 3710a644c7826..0c18b3a41c04c 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -1304,7 +1304,7 @@ def searchsorted( self, value: NumpyValueArrayLike | ExtensionArray, side: Literal["left", "right"] = "left", - sorter: NumpySorter = None, + sorter: NumpySorter | None = None, ) -> npt.NDArray[np.intp] | np.intp: if isinstance(value, ABCDataFrame): msg = ( diff --git a/pandas/core/dtypes/dtypes.py b/pandas/core/dtypes/dtypes.py index ea4d10c06efe3..aa721e405a3e8 100644 --- a/pandas/core/dtypes/dtypes.py +++ b/pandas/core/dtypes/dtypes.py @@ -219,7 +219,7 @@ def _from_fastpath( @classmethod def _from_categorical_dtype( - cls, dtype: CategoricalDtype, categories=None, ordered: Ordered = None + cls, dtype: CategoricalDtype, categories=None, ordered: Ordered | None = None ) -> CategoricalDtype: if categories is ordered is None: return dtype diff --git a/pandas/core/frame.py b/pandas/core/frame.py index ae43a44d68f1c..9d90a110ccea3 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -2572,7 +2572,7 @@ def to_stata( version: int | None = 114, convert_strl: Sequence[Hashable] | None = None, compression: CompressionOptions = "infer", - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, value_labels: dict[Hashable, dict[float, str]] | None = None, ) -> None: """ @@ -2767,7 +2767,7 @@ def to_markdown( buf: FilePath | WriteBuffer[str] | None = None, mode: str = "wt", index: bool = True, - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, **kwargs, ) -> str | None: if "showindex" in kwargs: @@ -2819,7 +2819,7 @@ def to_parquet( compression: str | None = "snappy", index: bool | None = None, partition_cols: list[str] | None = None, - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, **kwargs, ) -> bytes | None: """ @@ -3188,7 +3188,7 @@ def to_xml( parser: XMLParsers | None = "lxml", stylesheet: FilePath | ReadBuffer[str] | ReadBuffer[bytes] | None = None, compression: CompressionOptions = "infer", - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, ) -> str | None: """ Render a DataFrame to an XML document. @@ -5089,12 +5089,12 @@ def drop( def drop( self, - labels: IndexLabel = None, + labels: IndexLabel | None = None, *, axis: Axis = 0, - index: IndexLabel = None, - columns: IndexLabel = None, - level: Level = None, + index: IndexLabel | None = None, + columns: IndexLabel | None = None, + level: Level | None = None, inplace: bool = False, errors: IgnoreRaise = "raise", ) -> DataFrame | None: @@ -5299,7 +5299,7 @@ def rename( axis: Axis | None = None, copy: bool | None = None, inplace: bool = False, - level: Level = None, + level: Level | None = None, errors: IgnoreRaise = "ignore", ) -> DataFrame | None: """ @@ -5814,7 +5814,7 @@ def reset_index( col_level: Hashable = ..., col_fill: Hashable = ..., allow_duplicates: bool | lib.NoDefault = ..., - names: Hashable | Sequence[Hashable] = None, + names: Hashable | Sequence[Hashable] | None = None, ) -> DataFrame: ... @@ -5828,7 +5828,7 @@ def reset_index( col_level: Hashable = ..., col_fill: Hashable = ..., allow_duplicates: bool | lib.NoDefault = ..., - names: Hashable | Sequence[Hashable] = None, + names: Hashable | Sequence[Hashable] | None = None, ) -> None: ... @@ -5842,20 +5842,20 @@ def reset_index( col_level: Hashable = ..., col_fill: Hashable = ..., allow_duplicates: bool | lib.NoDefault = ..., - names: Hashable | Sequence[Hashable] = None, + names: Hashable | Sequence[Hashable] | None = None, ) -> DataFrame | None: ... def reset_index( self, - level: IndexLabel = None, + level: IndexLabel | None = None, *, drop: bool = False, inplace: bool = False, col_level: Hashable = 0, col_fill: Hashable = "", allow_duplicates: bool | lib.NoDefault = lib.no_default, - names: Hashable | Sequence[Hashable] = None, + names: Hashable | Sequence[Hashable] | None = None, ) -> DataFrame | None: """ Reset the index, or a level of it. @@ -6151,7 +6151,7 @@ def dropna( axis: Axis = 0, how: AnyAll | lib.NoDefault = lib.no_default, thresh: int | lib.NoDefault = lib.no_default, - subset: IndexLabel = None, + subset: IndexLabel | None = None, inplace: bool = False, ignore_index: bool = False, ) -> DataFrame | None: @@ -6588,7 +6588,7 @@ def sort_values( kind: SortKind = "quicksort", na_position: str = "last", ignore_index: bool = False, - key: ValueKeyFunc = None, + key: ValueKeyFunc | None = None, ) -> DataFrame | None: """ Sort by the values along either axis. @@ -6867,14 +6867,14 @@ def sort_index( self, *, axis: Axis = 0, - level: IndexLabel = None, + level: IndexLabel | None = None, ascending: bool | Sequence[bool] = True, inplace: bool = False, kind: SortKind = "quicksort", na_position: NaPosition = "last", sort_remaining: bool = True, ignore_index: bool = False, - key: IndexKeyFunc = None, + key: IndexKeyFunc | None = None, ) -> DataFrame | None: """ Sort object by labels (along an axis). @@ -7642,7 +7642,7 @@ def _should_reindex_frame_op(self, right, op, axis: int, fill_value, level) -> b return False def _align_for_op( - self, other, axis: AxisInt, flex: bool | None = False, level: Level = None + self, other, axis: AxisInt, flex: bool | None = False, level: Level | None = None ): """ Convert rhs to meet lhs dims if input is list, tuple or np.ndarray. @@ -9396,7 +9396,7 @@ def melt( value_vars=None, var_name=None, value_name: Hashable = "value", - col_level: Level = None, + col_level: Level | None = None, ignore_index: bool = True, ) -> DataFrame: return melt( diff --git a/pandas/core/generic.py b/pandas/core/generic.py index b806ddbaa89ba..ba34d71f7284b 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -2182,14 +2182,14 @@ def to_excel( columns: Sequence[Hashable] | None = None, header: Sequence[Hashable] | bool_t = True, index: bool_t = True, - index_label: IndexLabel = None, + index_label: IndexLabel | None = None, startrow: int = 0, startcol: int = 0, engine: Literal["openpyxl", "xlsxwriter"] | None = None, merge_cells: bool_t = True, inf_rep: str = "inf", freeze_panes: tuple[int, int] | None = None, - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, engine_kwargs: dict[str, Any] | None = None, ) -> None: """ @@ -2349,7 +2349,7 @@ def to_json( compression: CompressionOptions = "infer", index: bool_t | None = None, indent: int | None = None, - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, mode: Literal["a", "w"] = "w", ) -> str | None: """ @@ -2778,7 +2778,7 @@ def to_sql( schema: str | None = None, if_exists: Literal["fail", "replace", "append"] = "fail", index: bool_t = True, - index_label: IndexLabel = None, + index_label: IndexLabel | None = None, chunksize: int | None = None, dtype: DtypeArg | None = None, method: Literal["multi"] | Callable | None = None, @@ -3001,7 +3001,7 @@ def to_pickle( path: FilePath | WriteBuffer[bytes], compression: CompressionOptions = "infer", protocol: int = pickle.HIGHEST_PROTOCOL, - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, ) -> None: """ Pickle (serialize) object to file. @@ -3717,7 +3717,7 @@ def to_csv( escapechar: str | None = None, decimal: str = ".", errors: OpenFileErrors = "strict", - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, ) -> str | None: r""" Write object to a comma-separated values (csv) file. @@ -4069,7 +4069,7 @@ def xs( self, key: IndexLabel, axis: Axis = 0, - level: IndexLabel = None, + level: IndexLabel | None = None, drop_level: bool_t = True, ) -> Self: """ @@ -4652,11 +4652,11 @@ def drop( def drop( self, - labels: IndexLabel = None, + labels: IndexLabel | None = None, *, axis: Axis = 0, - index: IndexLabel = None, - columns: IndexLabel = None, + index: IndexLabel | None = None, + columns: IndexLabel | None = None, level: Level | None = None, inplace: bool_t = False, errors: IgnoreRaise = "raise", @@ -4992,7 +4992,7 @@ def sort_values( kind: SortKind = "quicksort", na_position: NaPosition = "last", ignore_index: bool_t = False, - key: ValueKeyFunc = None, + key: ValueKeyFunc | None = None, ) -> Self | None: """ Sort by the values along either axis. @@ -5187,14 +5187,14 @@ def sort_index( self, *, axis: Axis = 0, - level: IndexLabel = None, + level: IndexLabel | None = None, ascending: bool_t | Sequence[bool_t] = True, inplace: bool_t = False, kind: SortKind = "quicksort", na_position: NaPosition = "last", sort_remaining: bool_t = True, ignore_index: bool_t = False, - key: IndexKeyFunc = None, + key: IndexKeyFunc | None = None, ) -> Self | None: inplace = validate_bool_kwarg(inplace, "inplace") axis = self._get_axis_number(axis) @@ -6968,7 +6968,7 @@ def fillna( ) def fillna( self, - value: Hashable | Mapping | Series | DataFrame = None, + value: Hashable | Mapping | Series | DataFrame | None = None, *, method: FillnaOptions | None = None, axis: Axis | None = None, @@ -8591,7 +8591,7 @@ def asfreq( method: FillnaOptions | None = None, how: Literal["start", "end"] | None = None, normalize: bool_t = False, - fill_value: Hashable = None, + fill_value: Hashable | None = None, ) -> Self: """ Convert time series to specified frequency. @@ -8861,8 +8861,8 @@ def resample( label: Literal["right", "left"] | None = None, convention: Literal["start", "end", "s", "e"] = "start", kind: Literal["timestamp", "period"] | None = None, - on: Level = None, - level: Level = None, + on: Level | None = None, + level: Level | None = None, origin: str | TimestampConvertibleTypes = "start_day", offset: TimedeltaConvertibleTypes | None = None, group_keys: bool_t = False, @@ -9673,9 +9673,9 @@ def align( other: NDFrameT, join: AlignJoin = "outer", axis: Axis | None = None, - level: Level = None, + level: Level | None = None, copy: bool_t | None = None, - fill_value: Hashable = None, + fill_value: Hashable | None = None, method: FillnaOptions | None | lib.NoDefault = lib.no_default, limit: int | None | lib.NoDefault = lib.no_default, fill_axis: Axis | lib.NoDefault = lib.no_default, @@ -10276,7 +10276,7 @@ def where( *, inplace: bool_t = False, axis: Axis | None = None, - level: Level = None, + level: Level | None = None, ) -> Self | None: """ Replace values where the condition is {cond_rev}. @@ -10470,7 +10470,7 @@ def mask( *, inplace: bool_t = False, axis: Axis | None = None, - level: Level = None, + level: Level | None = None, ) -> Self | None: inplace = validate_bool_kwarg(inplace, "inplace") cond = common.apply_if_callable(cond, self) diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index e3aa97b448fe1..26589ac135b8b 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -2403,7 +2403,7 @@ def value_counts( def fillna( self, - value: Hashable | Mapping | Series | DataFrame = None, + value: Hashable | Mapping | Series | DataFrame | None = None, method: FillnaOptions | None = None, axis: Axis | None | lib.NoDefault = lib.no_default, inplace: bool = False, @@ -2778,7 +2778,7 @@ def cov( @doc(DataFrame.hist.__doc__) def hist( self, - column: IndexLabel = None, + column: IndexLabel | None = None, by=None, grid: bool = True, xlabelsize: int | None = None, diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index f03af387151b2..2cab46b4482f9 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -642,7 +642,7 @@ def _dtype_to_subclass(cls, dtype: DtypeObj): # See each method's docstring. @classmethod - def _simple_new(cls, values: ArrayLike, name: Hashable = None, refs=None) -> Self: + def _simple_new(cls, values: ArrayLike, name: Hashable | None = None, refs=None) -> Self: """ We require that we have a dtype compat for the values. If we are passed a non-dtype compat, then coerce using the constructor. @@ -1521,7 +1521,7 @@ def to_flat_index(self) -> Self: return self @final - def to_series(self, index=None, name: Hashable = None) -> Series: + def to_series(self, index=None, name: Hashable | None = None) -> Series: """ Create a Series with both index and values equal to the index keys. @@ -4529,7 +4529,7 @@ def join( other: Index, *, how: JoinHow = "left", - level: Level = None, + level: Level | None = None, return_indexers: bool = False, sort: bool = False, ) -> Index | tuple[Index, npt.NDArray[np.intp] | None, npt.NDArray[np.intp] | None]: diff --git a/pandas/core/indexes/category.py b/pandas/core/indexes/category.py index 9bd0bc98dc733..12acacbceaae5 100644 --- a/pandas/core/indexes/category.py +++ b/pandas/core/indexes/category.py @@ -208,7 +208,7 @@ def __new__( ordered=None, dtype: Dtype | None = None, copy: bool = False, - name: Hashable = None, + name: Hashable | None = None, ) -> CategoricalIndex: name = maybe_extract_name(name, data, cls) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index 1500bcef5d4d9..c8dafc568b7be 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -328,7 +328,7 @@ def __new__( yearfirst: bool = False, dtype: Dtype | None = None, copy: bool = False, - name: Hashable = None, + name: Hashable | None = None, ) -> Self: if closed is not lib.no_default: # GH#52628 @@ -809,7 +809,7 @@ def date_range( freq=None, tz=None, normalize: bool = False, - name: Hashable = None, + name: Hashable | None = None, inclusive: IntervalClosedType = "both", *, unit: str | None = None, @@ -1010,7 +1010,7 @@ def bdate_range( freq: Frequency = "B", tz=None, normalize: bool = True, - name: Hashable = None, + name: Hashable | None = None, weekmask=None, holidays=None, inclusive: IntervalClosedType = "both", diff --git a/pandas/core/indexes/interval.py b/pandas/core/indexes/interval.py index 50838f8c65881..7379b23428b95 100644 --- a/pandas/core/indexes/interval.py +++ b/pandas/core/indexes/interval.py @@ -222,7 +222,7 @@ def __new__( closed: IntervalClosedType | None = None, dtype: Dtype | None = None, copy: bool = False, - name: Hashable = None, + name: Hashable | None = None, verify_integrity: bool = True, ) -> IntervalIndex: name = maybe_extract_name(name, data, cls) @@ -263,7 +263,7 @@ def from_breaks( cls, breaks, closed: IntervalClosedType | None = "right", - name: Hashable = None, + name: Hashable | None = None, copy: bool = False, dtype: Dtype | None = None, ) -> IntervalIndex: @@ -299,7 +299,7 @@ def from_arrays( left, right, closed: IntervalClosedType = "right", - name: Hashable = None, + name: Hashable | None = None, copy: bool = False, dtype: Dtype | None = None, ) -> IntervalIndex: @@ -334,7 +334,7 @@ def from_tuples( cls, data, closed: IntervalClosedType = "right", - name: Hashable = None, + name: Hashable | None = None, copy: bool = False, dtype: Dtype | None = None, ) -> IntervalIndex: @@ -983,7 +983,7 @@ def interval_range( end=None, periods=None, freq=None, - name: Hashable = None, + name: Hashable | None = None, closed: IntervalClosedType = "right", ) -> IntervalIndex: """ diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index 824ffa5cf4c67..144bc6abdf4ca 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -546,7 +546,7 @@ def from_tuples( cls, tuples: Iterable[tuple[Hashable, ...]], sortorder: int | None = None, - names: Sequence[Hashable] | Hashable = None, + names: Sequence[Hashable] | Hashable | None = None, ) -> MultiIndex: """ Convert list of tuples to MultiIndex. diff --git a/pandas/core/indexes/period.py b/pandas/core/indexes/period.py index fd7cab0344e42..18b0504f6ce3c 100644 --- a/pandas/core/indexes/period.py +++ b/pandas/core/indexes/period.py @@ -213,7 +213,7 @@ def __new__( freq=None, dtype: Dtype | None = None, copy: bool = False, - name: Hashable = None, + name: Hashable | None = None, **fields, ) -> Self: valid_field_set = { @@ -467,7 +467,7 @@ def shift(self, periods: int = 1, freq=None) -> Self: def period_range( - start=None, end=None, periods: int | None = None, freq=None, name: Hashable = None + start=None, end=None, periods: int | None = None, freq=None, name: Hashable | None = None ) -> PeriodIndex: """ Return a fixed frequency PeriodIndex. diff --git a/pandas/core/indexes/range.py b/pandas/core/indexes/range.py index 2b0dc53a736ea..b404d6ef4fa65 100644 --- a/pandas/core/indexes/range.py +++ b/pandas/core/indexes/range.py @@ -136,7 +136,7 @@ def __new__( step=None, dtype: Dtype | None = None, copy: bool = False, - name: Hashable = None, + name: Hashable | None = None, ) -> RangeIndex: cls._validate_dtype(dtype) name = maybe_extract_name(name, start, cls) @@ -195,7 +195,7 @@ def from_range(cls, data: range, name=None, dtype: Dtype | None = None) -> Self: # "Union[ExtensionArray, ndarray[Any, Any]]" [override] @classmethod def _simple_new( # type: ignore[override] - cls, values: range, name: Hashable = None + cls, values: range, name: Hashable | None = None ) -> Self: result = object.__new__(cls) @@ -485,7 +485,7 @@ def _view(self) -> Self: return result @doc(Index.copy) - def copy(self, name: Hashable = None, deep: bool = False) -> Self: + def copy(self, name: Hashable | None = None, deep: bool = False) -> Self: name = self._validate_names(name=name, deep=deep)[0] new_index = self._rename(name=name) return new_index @@ -836,7 +836,7 @@ def _difference(self, other, sort=None): return new_index - def symmetric_difference(self, other, result_name: Hashable = None, sort=None): + def symmetric_difference(self, other, result_name: Hashable | None = None, sort=None): if not isinstance(other, RangeIndex) or sort is not None: return super().symmetric_difference(other, result_name, sort) diff --git a/pandas/core/series.py b/pandas/core/series.py index e59a4cfc3fcc1..efa4ef43fa657 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1507,7 +1507,7 @@ def reset_index( def reset_index( self, - level: IndexLabel = None, + level: IndexLabel | None = None, *, drop: bool = False, name: Level = lib.no_default, @@ -1819,7 +1819,7 @@ def to_markdown( buf: IO[str] | None = None, mode: str = "wt", index: bool = True, - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, **kwargs, ) -> str | None: """ @@ -2096,7 +2096,7 @@ def groupby( self, by=None, axis: Axis = 0, - level: IndexLabel = None, + level: IndexLabel | None = None, as_index: bool = True, sort: bool = True, group_keys: bool = True, @@ -3090,7 +3090,7 @@ def searchsorted( # type: ignore[override] self, value: NumpyValueArrayLike | ExtensionArray, side: Literal["left", "right"] = "left", - sorter: NumpySorter = None, + sorter: NumpySorter | None = None, ) -> npt.NDArray[np.intp] | np.intp: return base.IndexOpsMixin.searchsorted(self, value, side=side, sorter=sorter) @@ -3200,7 +3200,7 @@ def combine( self, other: Series | Hashable, func: Callable[[Hashable, Hashable], Hashable], - fill_value: Hashable = None, + fill_value: Hashable | None = None, ) -> Series: """ Combine the Series with a Series or scalar according to `func`. @@ -3475,7 +3475,7 @@ def sort_values( kind: SortKind = "quicksort", na_position: NaPosition = "last", ignore_index: bool = False, - key: ValueKeyFunc = None, + key: ValueKeyFunc | None = None, ) -> Series | None: """ Sort by the values. @@ -3719,14 +3719,14 @@ def sort_index( self, *, axis: Axis = 0, - level: IndexLabel = None, + level: IndexLabel | None = None, ascending: bool | Sequence[bool] = True, inplace: bool = False, kind: SortKind = "quicksort", na_position: NaPosition = "last", sort_remaining: bool = True, ignore_index: bool = False, - key: IndexKeyFunc = None, + key: IndexKeyFunc | None = None, ) -> Series | None: """ Sort Series by index labels. @@ -4315,7 +4315,7 @@ def explode(self, ignore_index: bool = False) -> Series: return self._constructor(values, index=index, name=self.name, copy=False) def unstack( - self, level: IndexLabel = -1, fill_value: Hashable = None, sort: bool = True + self, level: IndexLabel = -1, fill_value: Hashable | None = None, sort: bool = True ) -> DataFrame: """ Unstack, also known as pivot, Series with MultiIndex to produce DataFrame. @@ -4961,11 +4961,11 @@ def drop( def drop( self, - labels: IndexLabel = None, + labels: IndexLabel | None = None, *, axis: Axis = 0, - index: IndexLabel = None, - columns: IndexLabel = None, + index: IndexLabel | None = None, + columns: IndexLabel | None = None, level: Level | None = None, inplace: bool = False, errors: IgnoreRaise = "raise", diff --git a/pandas/core/tools/datetimes.py b/pandas/core/tools/datetimes.py index 13a434812db3b..bd065253b0108 100644 --- a/pandas/core/tools/datetimes.py +++ b/pandas/core/tools/datetimes.py @@ -261,7 +261,7 @@ def _maybe_cache( def _box_as_indexlike( - dt_array: ArrayLike, utc: bool = False, name: Hashable = None + dt_array: ArrayLike, utc: bool = False, name: Hashable | None = None ) -> Index: """ Properly boxes the ndarray of datetimes to DatetimeIndex @@ -353,7 +353,7 @@ def _return_parsed_timezone_results( def _convert_listlike_datetimes( arg, format: str | None, - name: Hashable = None, + name: Hashable | None = None, utc: bool = False, unit: str | None = None, errors: DateTimeErrorChoices = "raise", diff --git a/pandas/io/common.py b/pandas/io/common.py index 43780a08a4339..b3730e3f8afe5 100644 --- a/pandas/io/common.py +++ b/pandas/io/common.py @@ -289,9 +289,9 @@ def is_fsspec_url(url: FilePath | BaseBuffer) -> bool: def _get_filepath_or_buffer( filepath_or_buffer: FilePath | BaseBuffer, encoding: str = "utf-8", - compression: CompressionOptions = None, + compression: CompressionOptions | None = None, mode: str = "r", - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, ) -> IOArgs: """ If the filepath_or_buffer is a url, translate and return the buffer. @@ -651,11 +651,11 @@ def get_handle( mode: str, *, encoding: str | None = None, - compression: CompressionOptions = None, + compression: CompressionOptions | None = None, memory_map: bool = False, is_text: bool = True, errors: str | None = None, - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, ) -> IOHandles[str] | IOHandles[bytes]: """ Get file handle for given path/buffer and mode. diff --git a/pandas/io/excel/_base.py b/pandas/io/excel/_base.py index 8383449ff21f1..025a00e6470b6 100644 --- a/pandas/io/excel/_base.py +++ b/pandas/io/excel/_base.py @@ -484,7 +484,7 @@ def read_excel( decimal: str = ".", comment: str | None = None, skipfooter: int = 0, - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, dtype_backend: DtypeBackend | lib.NoDefault = lib.no_default, engine_kwargs: dict | None = None, ) -> DataFrame | dict[IntStrT, DataFrame]: @@ -544,7 +544,7 @@ class BaseExcelReader(metaclass=abc.ABCMeta): def __init__( self, filepath_or_buffer, - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, engine_kwargs: dict | None = None, ) -> None: if engine_kwargs is None: @@ -1126,7 +1126,7 @@ def __new__( date_format: str | None = None, datetime_format: str | None = None, mode: str = "w", - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, if_sheet_exists: Literal["error", "new", "replace", "overlay"] | None = None, engine_kwargs: dict | None = None, ) -> ExcelWriter: @@ -1215,7 +1215,7 @@ def __init__( date_format: str | None = None, datetime_format: str | None = None, mode: str = "w", - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, if_sheet_exists: str | None = None, engine_kwargs: dict[str, Any] | None = None, ) -> None: @@ -1371,7 +1371,7 @@ def close(self) -> None: @doc(storage_options=_shared_docs["storage_options"]) def inspect_excel_format( content_or_path: FilePath | ReadBuffer[bytes], - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, ) -> str | None: """ Inspect the path or content of an excel file and get its format. @@ -1504,7 +1504,7 @@ def __init__( self, path_or_buffer, engine: str | None = None, - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, engine_kwargs: dict | None = None, ) -> None: if engine_kwargs is None: diff --git a/pandas/io/excel/_odfreader.py b/pandas/io/excel/_odfreader.py index c46424d5b26da..16fb870e4700a 100644 --- a/pandas/io/excel/_odfreader.py +++ b/pandas/io/excel/_odfreader.py @@ -30,7 +30,7 @@ class ODFReader(BaseExcelReader): def __init__( self, filepath_or_buffer: FilePath | ReadBuffer[bytes], - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, engine_kwargs: dict | None = None, ) -> None: """ diff --git a/pandas/io/excel/_odswriter.py b/pandas/io/excel/_odswriter.py index f5aaf08530591..b72d7c5cd2726 100644 --- a/pandas/io/excel/_odswriter.py +++ b/pandas/io/excel/_odswriter.py @@ -39,7 +39,7 @@ def __init__( date_format: str | None = None, datetime_format=None, mode: str = "w", - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, if_sheet_exists: str | None = None, engine_kwargs: dict[str, Any] | None = None, **kwargs, diff --git a/pandas/io/excel/_openpyxl.py b/pandas/io/excel/_openpyxl.py index 195d3a3a8b263..700460d4d5da2 100644 --- a/pandas/io/excel/_openpyxl.py +++ b/pandas/io/excel/_openpyxl.py @@ -48,7 +48,7 @@ def __init__( date_format: str | None = None, datetime_format: str | None = None, mode: str = "w", - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, if_sheet_exists: str | None = None, engine_kwargs: dict[str, Any] | None = None, **kwargs, @@ -535,7 +535,7 @@ class OpenpyxlReader(BaseExcelReader): def __init__( self, filepath_or_buffer: FilePath | ReadBuffer[bytes], - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, engine_kwargs: dict | None = None, ) -> None: """ diff --git a/pandas/io/excel/_pyxlsb.py b/pandas/io/excel/_pyxlsb.py index a1234b0e74c3e..86805a0463c47 100644 --- a/pandas/io/excel/_pyxlsb.py +++ b/pandas/io/excel/_pyxlsb.py @@ -24,7 +24,7 @@ class PyxlsbReader(BaseExcelReader): def __init__( self, filepath_or_buffer: FilePath | ReadBuffer[bytes], - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, engine_kwargs: dict | None = None, ) -> None: """ diff --git a/pandas/io/excel/_xlrd.py b/pandas/io/excel/_xlrd.py index d131567cf70f7..cb0ff975af9bb 100644 --- a/pandas/io/excel/_xlrd.py +++ b/pandas/io/excel/_xlrd.py @@ -24,7 +24,7 @@ class XlrdReader(BaseExcelReader): def __init__( self, filepath_or_buffer, - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, engine_kwargs: dict | None = None, ) -> None: """ diff --git a/pandas/io/excel/_xlsxwriter.py b/pandas/io/excel/_xlsxwriter.py index d7262c2f62d94..fb0d452c69ca0 100644 --- a/pandas/io/excel/_xlsxwriter.py +++ b/pandas/io/excel/_xlsxwriter.py @@ -188,7 +188,7 @@ def __init__( date_format: str | None = None, datetime_format: str | None = None, mode: str = "w", - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, if_sheet_exists: str | None = None, engine_kwargs: dict[str, Any] | None = None, **kwargs, diff --git a/pandas/io/feather_format.py b/pandas/io/feather_format.py index 28df235084cf5..34306d4d1ab2d 100644 --- a/pandas/io/feather_format.py +++ b/pandas/io/feather_format.py @@ -32,7 +32,7 @@ def to_feather( df: DataFrame, path: FilePath | WriteBuffer[bytes], - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, **kwargs, ) -> None: """ @@ -67,7 +67,7 @@ def read_feather( path: FilePath | ReadBuffer[bytes], columns: Sequence[Hashable] | None = None, use_threads: bool = True, - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, dtype_backend: DtypeBackend | lib.NoDefault = lib.no_default, ): """ diff --git a/pandas/io/formats/csvs.py b/pandas/io/formats/csvs.py index 3b759010d1abb..42f6bc9cdff06 100644 --- a/pandas/io/formats/csvs.py +++ b/pandas/io/formats/csvs.py @@ -69,7 +69,7 @@ def __init__( date_format: str | None = None, doublequote: bool = True, escapechar: str | None = None, - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, ) -> None: self.fmt = formatter diff --git a/pandas/io/formats/excel.py b/pandas/io/formats/excel.py index 0dbb6529cd384..ddffdc7963b04 100644 --- a/pandas/io/formats/excel.py +++ b/pandas/io/formats/excel.py @@ -897,7 +897,7 @@ def write( startcol: int = 0, freeze_panes: tuple[int, int] | None = None, engine: str | None = None, - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, engine_kwargs: dict | None = None, ) -> None: """ diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index 8caa9d0cbd3a5..580ca7c2e565f 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -1116,7 +1116,7 @@ def to_csv( doublequote: bool = True, escapechar: str | None = None, errors: str = "strict", - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, ) -> str | None: """ Render dataframe as comma-separated file. diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index c599bcbfd4170..b4fe7d0d05279 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -520,7 +520,7 @@ def to_excel( inf_rep: str = "inf", verbose: bool = True, freeze_panes: tuple[int, int] | None = None, - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, ) -> None: from pandas.io.formats.excel import ExcelFormatter diff --git a/pandas/io/formats/xml.py b/pandas/io/formats/xml.py index 7927e27cc9284..01ef4b13c2137 100644 --- a/pandas/io/formats/xml.py +++ b/pandas/io/formats/xml.py @@ -117,7 +117,7 @@ def __init__( pretty_print: bool | None = True, stylesheet: FilePath | ReadBuffer[str] | ReadBuffer[bytes] | None = None, compression: CompressionOptions = "infer", - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, ) -> None: self.frame = frame self.path_or_buffer = path_or_buffer diff --git a/pandas/io/json/_json.py b/pandas/io/json/_json.py index eaeaedfdddfcb..304668553e473 100644 --- a/pandas/io/json/_json.py +++ b/pandas/io/json/_json.py @@ -143,7 +143,7 @@ def to_json( compression: CompressionOptions = "infer", index: bool | None = None, indent: int = 0, - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, mode: Literal["a", "w"] = "w", ) -> str | None: if orient in ["records", "values"] and index is True: @@ -516,7 +516,7 @@ def read_json( chunksize: int | None = None, compression: CompressionOptions = "infer", nrows: int | None = None, - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, dtype_backend: DtypeBackend | lib.NoDefault = lib.no_default, engine: JSONEngine = "ujson", ) -> DataFrame | Series | JsonReader: @@ -826,7 +826,7 @@ def __init__( chunksize: int | None, compression: CompressionOptions, nrows: int | None, - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, encoding_errors: str | None = "strict", dtype_backend: DtypeBackend | lib.NoDefault = lib.no_default, engine: JSONEngine = "ujson", diff --git a/pandas/io/parquet.py b/pandas/io/parquet.py index e8670757e1669..dd8d2ceaa7c3d 100644 --- a/pandas/io/parquet.py +++ b/pandas/io/parquet.py @@ -80,7 +80,7 @@ def get_engine(engine: str) -> BaseImpl: def _get_path_or_handle( path: FilePath | ReadBuffer[bytes] | WriteBuffer[bytes], fs: Any, - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, mode: str = "rb", is_dir: bool = False, ) -> tuple[ @@ -171,7 +171,7 @@ def write( path: FilePath | WriteBuffer[bytes], compression: str | None = "snappy", index: bool | None = None, - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, partition_cols: list[str] | None = None, filesystem=None, **kwargs, @@ -230,7 +230,7 @@ def read( columns=None, use_nullable_dtypes: bool = False, dtype_backend: DtypeBackend | lib.NoDefault = lib.no_default, - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, filesystem=None, **kwargs, ) -> DataFrame: @@ -285,7 +285,7 @@ def write( compression: Literal["snappy", "gzip", "brotli"] | None = "snappy", index=None, partition_cols=None, - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, filesystem=None, **kwargs, ) -> None: @@ -335,7 +335,7 @@ def read( self, path, columns=None, - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, filesystem=None, **kwargs, ) -> DataFrame: @@ -388,7 +388,7 @@ def to_parquet( engine: str = "auto", compression: str | None = "snappy", index: bool | None = None, - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, partition_cols: list[str] | None = None, filesystem: Any = None, **kwargs, @@ -483,7 +483,7 @@ def read_parquet( path: FilePath | ReadBuffer[bytes], engine: str = "auto", columns: list[str] | None = None, - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, use_nullable_dtypes: bool | lib.NoDefault = lib.no_default, dtype_backend: DtypeBackend | lib.NoDefault = lib.no_default, filesystem: Any = None, diff --git a/pandas/io/parsers/readers.py b/pandas/io/parsers/readers.py index 0e4f85bfe3d63..334f47568d5e0 100644 --- a/pandas/io/parsers/readers.py +++ b/pandas/io/parsers/readers.py @@ -911,7 +911,7 @@ def read_csv( low_memory: bool = _c_parser_defaults["low_memory"], memory_map: bool = False, float_precision: Literal["high", "legacy"] | None = None, - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, dtype_backend: DtypeBackend | lib.NoDefault = lib.no_default, ) -> DataFrame | TextFileReader: if infer_datetime_format is not lib.no_default: @@ -1244,7 +1244,7 @@ def read_table( low_memory: bool = _c_parser_defaults["low_memory"], memory_map: bool = False, float_precision: str | None = None, - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, dtype_backend: DtypeBackend | lib.NoDefault = lib.no_default, ) -> DataFrame | TextFileReader: if infer_datetime_format is not lib.no_default: diff --git a/pandas/io/pickle.py b/pandas/io/pickle.py index ba837e2f57243..04e0cbc3d289d 100644 --- a/pandas/io/pickle.py +++ b/pandas/io/pickle.py @@ -34,7 +34,7 @@ def to_pickle( filepath_or_buffer: FilePath | WriteBuffer[bytes], compression: CompressionOptions = "infer", protocol: int = pickle.HIGHEST_PROTOCOL, - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, ) -> None: """ Pickle (serialize) object to file. @@ -115,7 +115,7 @@ def to_pickle( def read_pickle( filepath_or_buffer: FilePath | ReadPickleBuffer, compression: CompressionOptions = "infer", - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, ): """ Load pickled pandas object (or any object) from file. diff --git a/pandas/io/sql.py b/pandas/io/sql.py index 719479754340b..55b6cf8d6a481 100644 --- a/pandas/io/sql.py +++ b/pandas/io/sql.py @@ -685,7 +685,7 @@ def to_sql( schema: str | None = None, if_exists: Literal["fail", "replace", "append"] = "fail", index: bool = True, - index_label: IndexLabel = None, + index_label: IndexLabel | None = None, chunksize: int | None = None, dtype: DtypeArg | None = None, method: Literal["multi"] | Callable | None = None, diff --git a/pandas/io/stata.py b/pandas/io/stata.py index d62830ffe3ea1..1eb724b65f44e 100644 --- a/pandas/io/stata.py +++ b/pandas/io/stata.py @@ -1133,7 +1133,7 @@ def __init__( order_categoricals: bool = True, chunksize: int | None = None, compression: CompressionOptions = "infer", - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, ) -> None: super().__init__() self._col_sizes: list[int] = [] @@ -2080,7 +2080,7 @@ def read_stata( chunksize: int | None = None, iterator: bool = False, compression: CompressionOptions = "infer", - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, ) -> DataFrame | StataReader: reader = StataReader( filepath_or_buffer, @@ -2340,7 +2340,7 @@ def __init__( data_label: str | None = None, variable_labels: dict[Hashable, str] | None = None, compression: CompressionOptions = "infer", - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, *, value_labels: dict[Hashable, dict[float, str]] | None = None, ) -> None: @@ -3267,7 +3267,7 @@ def __init__( variable_labels: dict[Hashable, str] | None = None, convert_strl: Sequence[Hashable] | None = None, compression: CompressionOptions = "infer", - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, *, value_labels: dict[Hashable, dict[float, str]] | None = None, ) -> None: @@ -3659,7 +3659,7 @@ def __init__( convert_strl: Sequence[Hashable] | None = None, version: int | None = None, compression: CompressionOptions = "infer", - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, *, value_labels: dict[Hashable, dict[float, str]] | None = None, ) -> None: diff --git a/pandas/io/xml.py b/pandas/io/xml.py index 2aec361d46b99..66065ab11e662 100644 --- a/pandas/io/xml.py +++ b/pandas/io/xml.py @@ -878,7 +878,7 @@ def read_xml( stylesheet: FilePath | ReadBuffer[bytes] | ReadBuffer[str] | None = None, iterparse: dict[str, list[str]] | None = None, compression: CompressionOptions = "infer", - storage_options: StorageOptions = None, + storage_options: StorageOptions | None = None, dtype_backend: DtypeBackend | lib.NoDefault = lib.no_default, ) -> DataFrame: r""" diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index 24b8816109677..ee8dec721d358 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -128,7 +128,7 @@ def hist_series( def hist_frame( data: DataFrame, - column: IndexLabel = None, + column: IndexLabel | None = None, by=None, grid: bool = True, xlabelsize: int | None = None, @@ -1059,7 +1059,7 @@ def __call__(self, *args, **kwargs): ) @Substitution(kind="line") @Appender(_bar_or_line_doc) - def line(self, x: Hashable = None, y: Hashable = None, **kwargs) -> PlotAccessor: + def line(self, x: Hashable | None = None, y: Hashable | None = None, **kwargs) -> PlotAccessor: """ Plot Series or DataFrame as lines. @@ -1147,7 +1147,7 @@ def line(self, x: Hashable = None, y: Hashable = None, **kwargs) -> PlotAccessor @Substitution(kind="bar") @Appender(_bar_or_line_doc) def bar( # pylint: disable=disallowed-name - self, x: Hashable = None, y: Hashable = None, **kwargs + self, x: Hashable | None = None, y: Hashable | None = None, **kwargs ) -> PlotAccessor: """ Vertical bar plot. @@ -1234,7 +1234,7 @@ def bar( # pylint: disable=disallowed-name ) @Substitution(kind="bar") @Appender(_bar_or_line_doc) - def barh(self, x: Hashable = None, y: Hashable = None, **kwargs) -> PlotAccessor: + def barh(self, x: Hashable | None = None, y: Hashable | None = None, **kwargs) -> PlotAccessor: """ Make a horizontal bar plot. @@ -1246,7 +1246,7 @@ def barh(self, x: Hashable = None, y: Hashable = None, **kwargs) -> PlotAccessor """ return self(kind="barh", x=x, y=y, **kwargs) - def box(self, by: IndexLabel = None, **kwargs) -> PlotAccessor: + def box(self, by: IndexLabel | None = None, **kwargs) -> PlotAccessor: r""" Make a box plot of the DataFrame columns. @@ -1313,7 +1313,7 @@ def box(self, by: IndexLabel = None, **kwargs) -> PlotAccessor: """ return self(kind="box", by=by, **kwargs) - def hist(self, by: IndexLabel = None, bins: int = 10, **kwargs) -> PlotAccessor: + def hist(self, by: IndexLabel | None = None, bins: int = 10, **kwargs) -> PlotAccessor: """ Draw one histogram of the DataFrame's columns. @@ -1491,7 +1491,7 @@ def kde( density = kde def area( - self, x: Hashable = None, y: Hashable = None, stacked: bool = True, **kwargs + self, x: Hashable | None = None, y: Hashable | None = None, stacked: bool = True, **kwargs ) -> PlotAccessor: """ Draw a stacked area plot. @@ -1624,8 +1624,8 @@ def scatter( self, x: Hashable, y: Hashable, - s: Hashable | Sequence[Hashable] = None, - c: Hashable | Sequence[Hashable] = None, + s: Hashable | Sequence[Hashable] | None = None, + c: Hashable | Sequence[Hashable] | None = None, **kwargs, ) -> PlotAccessor: """ @@ -1714,7 +1714,7 @@ def hexbin( self, x: Hashable, y: Hashable, - C: Hashable = None, + C: Hashable | None = None, reduce_C_function: Callable | None = None, gridsize: int | tuple[int, int] | None = None, **kwargs, From 81a946e0f6107e2f44a0a83081171210b4fdcc4c Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Fri, 7 Jul 2023 13:08:57 -0700 Subject: [PATCH 2/4] add codespell, ignore RUF012 --- pandas/_libs/algos.pyi | 2 -- pandas/core/frame.py | 6 +++++- pandas/core/indexes/base.py | 4 +++- pandas/core/indexes/period.py | 6 +++++- pandas/core/indexes/range.py | 4 +++- pandas/core/series.py | 5 ++++- pandas/plotting/_core.py | 18 ++++++++++++++---- pyproject.toml | 6 ++++-- 8 files changed, 38 insertions(+), 13 deletions(-) diff --git a/pandas/_libs/algos.pyi b/pandas/_libs/algos.pyi index 1177b6b8fe357..caf5425dfc7b4 100644 --- a/pandas/_libs/algos.pyi +++ b/pandas/_libs/algos.pyi @@ -5,7 +5,6 @@ import numpy as np from pandas._typing import npt class Infinity: - def __eq__(self, other) -> bool: ... def __ne__(self, other) -> bool: ... def __lt__(self, other) -> bool: ... @@ -14,7 +13,6 @@ class Infinity: def __ge__(self, other) -> bool: ... class NegInfinity: - def __eq__(self, other) -> bool: ... def __ne__(self, other) -> bool: ... def __lt__(self, other) -> bool: ... diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 8ec3721887ddb..0b953112429fa 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -7631,7 +7631,11 @@ def _should_reindex_frame_op(self, right, op, axis: int, fill_value, level) -> b return False def _align_for_op( - self, other, axis: AxisInt, flex: bool | None = False, level: Level | None = None + self, + other, + axis: AxisInt, + flex: bool | None = False, + level: Level | None = None, ): """ Convert rhs to meet lhs dims if input is list, tuple or np.ndarray. diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 67b24c3ae9155..f358d8a4cea94 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -642,7 +642,9 @@ def _dtype_to_subclass(cls, dtype: DtypeObj): # See each method's docstring. @classmethod - def _simple_new(cls, values: ArrayLike, name: Hashable | None = None, refs=None) -> Self: + def _simple_new( + cls, values: ArrayLike, name: Hashable | None = None, refs=None + ) -> Self: """ We require that we have a dtype compat for the values. If we are passed a non-dtype compat, then coerce using the constructor. diff --git a/pandas/core/indexes/period.py b/pandas/core/indexes/period.py index 18b0504f6ce3c..922980e4bf52e 100644 --- a/pandas/core/indexes/period.py +++ b/pandas/core/indexes/period.py @@ -467,7 +467,11 @@ def shift(self, periods: int = 1, freq=None) -> Self: def period_range( - start=None, end=None, periods: int | None = None, freq=None, name: Hashable | None = None + start=None, + end=None, + periods: int | None = None, + freq=None, + name: Hashable | None = None, ) -> PeriodIndex: """ Return a fixed frequency PeriodIndex. diff --git a/pandas/core/indexes/range.py b/pandas/core/indexes/range.py index b404d6ef4fa65..6204ff77037a4 100644 --- a/pandas/core/indexes/range.py +++ b/pandas/core/indexes/range.py @@ -836,7 +836,9 @@ def _difference(self, other, sort=None): return new_index - def symmetric_difference(self, other, result_name: Hashable | None = None, sort=None): + def symmetric_difference( + self, other, result_name: Hashable | None = None, sort=None + ): if not isinstance(other, RangeIndex) or sort is not None: return super().symmetric_difference(other, result_name, sort) diff --git a/pandas/core/series.py b/pandas/core/series.py index a94fd79bb8dfb..acfa8a6dbe071 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -4320,7 +4320,10 @@ def explode(self, ignore_index: bool = False) -> Series: return self._constructor(values, index=index, name=self.name, copy=False) def unstack( - self, level: IndexLabel = -1, fill_value: Hashable | None = None, sort: bool = True + self, + level: IndexLabel = -1, + fill_value: Hashable | None = None, + sort: bool = True, ) -> DataFrame: """ Unstack, also known as pivot, Series with MultiIndex to produce DataFrame. diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index ee8dec721d358..f74032601ca59 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -1059,7 +1059,9 @@ def __call__(self, *args, **kwargs): ) @Substitution(kind="line") @Appender(_bar_or_line_doc) - def line(self, x: Hashable | None = None, y: Hashable | None = None, **kwargs) -> PlotAccessor: + def line( + self, x: Hashable | None = None, y: Hashable | None = None, **kwargs + ) -> PlotAccessor: """ Plot Series or DataFrame as lines. @@ -1234,7 +1236,9 @@ def bar( # pylint: disable=disallowed-name ) @Substitution(kind="bar") @Appender(_bar_or_line_doc) - def barh(self, x: Hashable | None = None, y: Hashable | None = None, **kwargs) -> PlotAccessor: + def barh( + self, x: Hashable | None = None, y: Hashable | None = None, **kwargs + ) -> PlotAccessor: """ Make a horizontal bar plot. @@ -1313,7 +1317,9 @@ def box(self, by: IndexLabel | None = None, **kwargs) -> PlotAccessor: """ return self(kind="box", by=by, **kwargs) - def hist(self, by: IndexLabel | None = None, bins: int = 10, **kwargs) -> PlotAccessor: + def hist( + self, by: IndexLabel | None = None, bins: int = 10, **kwargs + ) -> PlotAccessor: """ Draw one histogram of the DataFrame's columns. @@ -1491,7 +1497,11 @@ def kde( density = kde def area( - self, x: Hashable | None = None, y: Hashable | None = None, stacked: bool = True, **kwargs + self, + x: Hashable | None = None, + y: Hashable | None = None, + stacked: bool = True, + **kwargs, ) -> PlotAccessor: """ Draw a stacked area plot. diff --git a/pyproject.toml b/pyproject.toml index a2ae269c26667..b9cbf1628e443 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -321,7 +321,9 @@ ignore = [ # pairwise-over-zipped (>=PY310 only) "RUF007", # explicit-f-string-type-conversion - "RUF010" + "RUF010", + # mutable-class-default + "RUF012" ] exclude = [ @@ -642,5 +644,5 @@ exclude_lines = [ directory = "coverage_html_report" [tool.codespell] -ignore-words-list = "blocs, coo, hist, nd, sav, ser, recuse, nin, timere" +ignore-words-list = "blocs, coo, hist, nd, sav, ser, recuse, nin, timere, afile, foor, aas, mis" ignore-regex = 'https://([\w/\.])+' From aca9e8e41d9be4ddacbab666b58a8a0db8f7d6be Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Fri, 7 Jul 2023 13:36:19 -0700 Subject: [PATCH 3/4] noqa RUF011, ignore another ruff code --- pandas/io/formats/xml.py | 12 ++++++++++-- pyproject.toml | 2 ++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/pandas/io/formats/xml.py b/pandas/io/formats/xml.py index 01ef4b13c2137..5725975bb6278 100644 --- a/pandas/io/formats/xml.py +++ b/pandas/io/formats/xml.py @@ -252,10 +252,18 @@ def other_namespaces(self) -> dict: nmsp_dict: dict[str, str] = {} if self.namespaces and self.prefix is None: - nmsp_dict = {"xmlns": n for p, n in self.namespaces.items() if p != ""} + nmsp_dict = { + "xmlns": n # noqa: RUF011 + for p, n in self.namespaces.items() + if p != "" + } if self.namespaces and self.prefix: - nmsp_dict = {"xmlns": n for p, n in self.namespaces.items() if p == ""} + nmsp_dict = { + "xmlns": n # noqa: RUF011 + for p, n in self.namespaces.items() + if p == "" + } return nmsp_dict diff --git a/pyproject.toml b/pyproject.toml index b9cbf1628e443..62b65b6e91c13 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -308,6 +308,8 @@ ignore = [ "B904", # Magic number "PLR2004", + # comparison-with-itself + "PLR0124", # Consider `elif` instead of `else` then `if` to remove indentation level "PLR5501", # ambiguous-unicode-character-string From fc56243e60d4d19eb178a291b3eab7c25f11316e Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Mon, 10 Jul 2023 13:41:03 -0700 Subject: [PATCH 4/4] Rename --- .../tests/groupby/transform/test_transform.py | 8 ++++---- .../tests/indexes/multi/test_constructors.py | 2 +- pandas/tests/io/parser/test_read_fwf.py | 4 ++-- pandas/tests/io/test_fsspec.py | 20 +++++++++---------- pandas/tests/io/test_pickle.py | 2 +- pyproject.toml | 2 +- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/pandas/tests/groupby/transform/test_transform.py b/pandas/tests/groupby/transform/test_transform.py index c84ee3114b71f..cfa336907e71a 100644 --- a/pandas/tests/groupby/transform/test_transform.py +++ b/pandas/tests/groupby/transform/test_transform.py @@ -875,16 +875,16 @@ def test_transform_with_non_scalar_group(): cols = MultiIndex.from_tuples( [ ("syn", "A"), - ("mis", "A"), + ("foo", "A"), ("non", "A"), ("syn", "C"), - ("mis", "C"), + ("foo", "C"), ("non", "C"), ("syn", "T"), - ("mis", "T"), + ("foo", "T"), ("non", "T"), ("syn", "G"), - ("mis", "G"), + ("foo", "G"), ("non", "G"), ] ) diff --git a/pandas/tests/indexes/multi/test_constructors.py b/pandas/tests/indexes/multi/test_constructors.py index cabc2bfd61db6..91ec1b2475cde 100644 --- a/pandas/tests/indexes/multi/test_constructors.py +++ b/pandas/tests/indexes/multi/test_constructors.py @@ -59,7 +59,7 @@ def test_constructor_nonhashable_names(): codes=[[0, 0, 1, 1], [0, 1, 0, 1]], names=("foo", "bar"), ) - renamed = [["foor"], ["barr"]] + renamed = [["fooo"], ["barr"]] with pytest.raises(TypeError, match=msg): mi.rename(names=renamed) diff --git a/pandas/tests/io/parser/test_read_fwf.py b/pandas/tests/io/parser/test_read_fwf.py index 7f622295472e4..47794c09bf541 100644 --- a/pandas/tests/io/parser/test_read_fwf.py +++ b/pandas/tests/io/parser/test_read_fwf.py @@ -695,10 +695,10 @@ def test_binary_mode(): GH 18035. """ - data = """aas aas aas + data = """aaa aaa aaa bba bab b a""" df_reference = DataFrame( - [["bba", "bab", "b a"]], columns=["aas", "aas.1", "aas.2"], index=[0] + [["bba", "bab", "b a"]], columns=["aaa", "aaa.1", "aaa.2"], index=[0] ) with tm.ensure_clean() as path: Path(path).write_text(data) diff --git a/pandas/tests/io/test_fsspec.py b/pandas/tests/io/test_fsspec.py index a1cde9f2f7e61..fe5818620b9a9 100644 --- a/pandas/tests/io/test_fsspec.py +++ b/pandas/tests/io/test_fsspec.py @@ -247,18 +247,18 @@ def test_not_present_exception(): @td.skip_if_no("pyarrow") def test_feather_options(fsspectest): df = DataFrame({"a": [0]}) - df.to_feather("testmem://afile", storage_options={"test": "feather_write"}) + df.to_feather("testmem://mockfile", storage_options={"test": "feather_write"}) assert fsspectest.test[0] == "feather_write" - out = read_feather("testmem://afile", storage_options={"test": "feather_read"}) + out = read_feather("testmem://mockfile", storage_options={"test": "feather_read"}) assert fsspectest.test[0] == "feather_read" tm.assert_frame_equal(df, out) def test_pickle_options(fsspectest): df = DataFrame({"a": [0]}) - df.to_pickle("testmem://afile", storage_options={"test": "pickle_write"}) + df.to_pickle("testmem://mockfile", storage_options={"test": "pickle_write"}) assert fsspectest.test[0] == "pickle_write" - out = read_pickle("testmem://afile", storage_options={"test": "pickle_read"}) + out = read_pickle("testmem://mockfile", storage_options={"test": "pickle_read"}) assert fsspectest.test[0] == "pickle_read" tm.assert_frame_equal(df, out) @@ -266,13 +266,13 @@ def test_pickle_options(fsspectest): def test_json_options(fsspectest, compression): df = DataFrame({"a": [0]}) df.to_json( - "testmem://afile", + "testmem://mockfile", compression=compression, storage_options={"test": "json_write"}, ) assert fsspectest.test[0] == "json_write" out = read_json( - "testmem://afile", + "testmem://mockfile", compression=compression, storage_options={"test": "json_read"}, ) @@ -283,10 +283,10 @@ def test_json_options(fsspectest, compression): def test_stata_options(fsspectest): df = DataFrame({"a": [0]}) df.to_stata( - "testmem://afile", storage_options={"test": "stata_write"}, write_index=False + "testmem://mockfile", storage_options={"test": "stata_write"}, write_index=False ) assert fsspectest.test[0] == "stata_write" - out = read_stata("testmem://afile", storage_options={"test": "stata_read"}) + out = read_stata("testmem://mockfile", storage_options={"test": "stata_read"}) assert fsspectest.test[0] == "stata_read" tm.assert_frame_equal(df, out.astype("int64")) @@ -294,9 +294,9 @@ def test_stata_options(fsspectest): @td.skip_if_no("tabulate") def test_markdown_options(fsspectest): df = DataFrame({"a": [0]}) - df.to_markdown("testmem://afile", storage_options={"test": "md_write"}) + df.to_markdown("testmem://mockfile", storage_options={"test": "md_write"}) assert fsspectest.test[0] == "md_write" - assert fsspectest.cat("testmem://afile") + assert fsspectest.cat("testmem://mockfile") @td.skip_if_no("pyarrow") diff --git a/pandas/tests/io/test_pickle.py b/pandas/tests/io/test_pickle.py index 60506aa2fbd0a..71ff029ed2201 100644 --- a/pandas/tests/io/test_pickle.py +++ b/pandas/tests/io/test_pickle.py @@ -459,7 +459,7 @@ def mock_urlopen_read(*args, **kwargs): @td.skip_if_no("fsspec") def test_pickle_fsspec_roundtrip(): with tm.ensure_clean(): - mockurl = "memory://afile" + mockurl = "memory://mockfile" df = tm.makeDataFrame() df.to_pickle(mockurl) result = pd.read_pickle(mockurl) diff --git a/pyproject.toml b/pyproject.toml index 62b65b6e91c13..64bc5e55ebd64 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -646,5 +646,5 @@ exclude_lines = [ directory = "coverage_html_report" [tool.codespell] -ignore-words-list = "blocs, coo, hist, nd, sav, ser, recuse, nin, timere, afile, foor, aas, mis" +ignore-words-list = "blocs, coo, hist, nd, sav, ser, recuse, nin, timere" ignore-regex = 'https://([\w/\.])+'