diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4b02ad7cf886f..6033bda99e8c8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,11 +18,6 @@ ci: # manual stage hooks skip: [pylint, pyright, mypy] repos: -- repo: https://github.com/hauntsaninja/black-pre-commit-mirror - # black compiled with mypyc - rev: 23.11.0 - hooks: - - id: black - repo: https://github.com/astral-sh/ruff-pre-commit rev: v0.1.6 hooks: @@ -35,6 +30,9 @@ repos: files: ^pandas exclude: ^pandas/tests args: [--select, "ANN001,ANN2", --fix-only, --exit-non-zero-on-fix] + - id: ruff-format + # TODO: "." not needed in ruff 0.1.8 + args: ["."] - repo: https://github.com/jendrikseipp/vulture rev: 'v2.10' hooks: diff --git a/asv_bench/benchmarks/indexing.py b/asv_bench/benchmarks/indexing.py index 9ad1f5b31016d..86da26bead64d 100644 --- a/asv_bench/benchmarks/indexing.py +++ b/asv_bench/benchmarks/indexing.py @@ -84,9 +84,7 @@ def time_loc_slice(self, index, index_structure): class NumericMaskedIndexing: monotonic_list = list(range(10**6)) - non_monotonic_list = ( - list(range(50)) + [54, 53, 52, 51] + list(range(55, 10**6 - 1)) - ) + non_monotonic_list = list(range(50)) + [54, 53, 52, 51] + list(range(55, 10**6 - 1)) params = [ ("Int64", "UInt64", "Float64"), diff --git a/asv_bench/benchmarks/io/style.py b/asv_bench/benchmarks/io/style.py index af9eef337e78e..24fd8a0d20aba 100644 --- a/asv_bench/benchmarks/io/style.py +++ b/asv_bench/benchmarks/io/style.py @@ -76,7 +76,8 @@ def _style_format(self): # apply a formatting function # subset is flexible but hinders vectorised solutions self.st = self.df.style.format( - "{:,.3f}", subset=IndexSlice["row_1":f"row_{ir}", "float_1":f"float_{ic}"] + "{:,.3f}", + subset=IndexSlice["row_1" : f"row_{ir}", "float_1" : f"float_{ic}"], ) def _style_apply_format_hide(self): diff --git a/doc/source/development/contributing_codebase.rst b/doc/source/development/contributing_codebase.rst index be8249cd3a287..7e0b9c3200d3b 100644 --- a/doc/source/development/contributing_codebase.rst +++ b/doc/source/development/contributing_codebase.rst @@ -38,7 +38,7 @@ Pre-commit ---------- Additionally, :ref:`Continuous Integration ` will run code formatting checks -like ``black``, ``ruff``, +like ``ruff``, ``isort``, and ``clang-format`` and more using `pre-commit hooks `_. Any warnings from these checks will cause the :ref:`Continuous Integration ` to fail; therefore, it is helpful to run the check yourself before submitting code. This diff --git a/pandas/_libs/hashtable.pyi b/pandas/_libs/hashtable.pyi index 3bb957812f0ed..3725bfa3362d9 100644 --- a/pandas/_libs/hashtable.pyi +++ b/pandas/_libs/hashtable.pyi @@ -196,7 +196,7 @@ class HashTable: *, return_inverse: Literal[True], mask: None = ..., - ) -> tuple[np.ndarray, npt.NDArray[np.intp],]: ... # np.ndarray[subclass-specific] + ) -> tuple[np.ndarray, npt.NDArray[np.intp]]: ... # np.ndarray[subclass-specific] @overload def unique( self, @@ -204,7 +204,10 @@ class HashTable: *, return_inverse: Literal[False] = ..., mask: npt.NDArray[np.bool_], - ) -> tuple[np.ndarray, npt.NDArray[np.bool_],]: ... # np.ndarray[subclass-specific] + ) -> tuple[ + np.ndarray, + npt.NDArray[np.bool_], + ]: ... # np.ndarray[subclass-specific] def factorize( self, values: np.ndarray, # np.ndarray[subclass-specific] diff --git a/pandas/_libs/lib.pyi b/pandas/_libs/lib.pyi index b9fd970e68f5b..32ecd264262d6 100644 --- a/pandas/_libs/lib.pyi +++ b/pandas/_libs/lib.pyi @@ -179,7 +179,8 @@ def indices_fast( sorted_labels: list[npt.NDArray[np.int64]], ) -> dict[Hashable, npt.NDArray[np.intp]]: ... def generate_slices( - labels: np.ndarray, ngroups: int # const intp_t[:] + labels: np.ndarray, + ngroups: int, # const intp_t[:] ) -> tuple[npt.NDArray[np.int64], npt.NDArray[np.int64]]: ... def count_level_2d( mask: np.ndarray, # ndarray[uint8_t, ndim=2, cast=True], @@ -209,5 +210,6 @@ def get_reverse_indexer( def is_bool_list(obj: list) -> bool: ... def dtypes_all_equal(types: list[DtypeObj]) -> bool: ... def is_range_indexer( - left: np.ndarray, n: int # np.ndarray[np.int64, ndim=1] + left: np.ndarray, + n: int, # np.ndarray[np.int64, ndim=1] ) -> bool: ... diff --git a/pandas/_testing/_hypothesis.py b/pandas/_testing/_hypothesis.py index 084ca9c306d19..f9f653f636c4c 100644 --- a/pandas/_testing/_hypothesis.py +++ b/pandas/_testing/_hypothesis.py @@ -54,12 +54,8 @@ DATETIME_NO_TZ = st.datetimes() DATETIME_JAN_1_1900_OPTIONAL_TZ = st.datetimes( - min_value=pd.Timestamp( - 1900, 1, 1 - ).to_pydatetime(), # pyright: ignore[reportGeneralTypeIssues] - max_value=pd.Timestamp( - 1900, 1, 1 - ).to_pydatetime(), # pyright: ignore[reportGeneralTypeIssues] + min_value=pd.Timestamp(1900, 1, 1).to_pydatetime(), # pyright: ignore[reportGeneralTypeIssues] + max_value=pd.Timestamp(1900, 1, 1).to_pydatetime(), # pyright: ignore[reportGeneralTypeIssues] timezones=st.one_of(st.none(), dateutil_timezones(), pytz_timezones()), ) diff --git a/pandas/core/apply.py b/pandas/core/apply.py index 784e11415ade6..5b2293aeebbe7 100644 --- a/pandas/core/apply.py +++ b/pandas/core/apply.py @@ -1010,7 +1010,8 @@ def wrapper(*args, **kwargs): # [..., Any] | str] | dict[Hashable,Callable[..., Any] | str | # list[Callable[..., Any] | str]]"; expected "Hashable" nb_looper = generate_apply_looper( - self.func, **engine_kwargs # type: ignore[arg-type] + self.func, # type: ignore[arg-type] + **engine_kwargs, ) result = nb_looper(self.values, self.axis) # If we made the result 2-D, squeeze it back to 1-D diff --git a/pandas/core/arrays/_arrow_string_mixins.py b/pandas/core/arrays/_arrow_string_mixins.py index bfff19a123a08..06c74290bd82e 100644 --- a/pandas/core/arrays/_arrow_string_mixins.py +++ b/pandas/core/arrays/_arrow_string_mixins.py @@ -58,7 +58,8 @@ def _str_get(self, i: int) -> Self: self._pa_array, start=start, stop=stop, step=step ) null_value = pa.scalar( - None, type=self._pa_array.type # type: ignore[attr-defined] + None, + type=self._pa_array.type, # type: ignore[attr-defined] ) result = pc.if_else(not_out_of_bounds, selected, null_value) return type(self)(result) diff --git a/pandas/core/arrays/_mixins.py b/pandas/core/arrays/_mixins.py index 0da121c36644a..560845d375b56 100644 --- a/pandas/core/arrays/_mixins.py +++ b/pandas/core/arrays/_mixins.py @@ -347,7 +347,9 @@ def fillna( # error: Argument 2 to "check_value_size" has incompatible type # "ExtensionArray"; expected "ndarray" value = missing.check_value_size( - value, mask, len(self) # type: ignore[arg-type] + value, + mask, # type: ignore[arg-type] + len(self), ) if mask.any(): diff --git a/pandas/core/arrays/arrow/array.py b/pandas/core/arrays/arrow/array.py index f90a4691ec263..1d0f5c60de64f 100644 --- a/pandas/core/arrays/arrow/array.py +++ b/pandas/core/arrays/arrow/array.py @@ -2855,7 +2855,8 @@ def _dt_tz_localize( "shift_backward": "earliest", "shift_forward": "latest", }.get( - nonexistent, None # type: ignore[arg-type] + nonexistent, # type: ignore[arg-type] + None, ) if nonexistent_pa is None: raise NotImplementedError(f"{nonexistent=} is not supported") diff --git a/pandas/core/arrays/base.py b/pandas/core/arrays/base.py index 5f3d66d17a9bc..58264f2aef6f3 100644 --- a/pandas/core/arrays/base.py +++ b/pandas/core/arrays/base.py @@ -1121,7 +1121,9 @@ def fillna( # error: Argument 2 to "check_value_size" has incompatible type # "ExtensionArray"; expected "ndarray" value = missing.check_value_size( - value, mask, len(self) # type: ignore[arg-type] + value, + mask, # type: ignore[arg-type] + len(self), ) if mask.any(): @@ -1490,9 +1492,7 @@ def factorize( uniques_ea = self._from_factorized(uniques, self) return codes, uniques_ea - _extension_array_shared_docs[ - "repeat" - ] = """ + _extension_array_shared_docs["repeat"] = """ Repeat elements of a %(klass)s. Returns a new %(klass)s where each element of the current %(klass)s diff --git a/pandas/core/arrays/datetimelike.py b/pandas/core/arrays/datetimelike.py index 4668db8d75cd7..44049f73b792b 100644 --- a/pandas/core/arrays/datetimelike.py +++ b/pandas/core/arrays/datetimelike.py @@ -1236,7 +1236,9 @@ def _add_timedeltalike(self, other: Timedelta | TimedeltaArray) -> Self: # error: Unexpected keyword argument "freq" for "_simple_new" of "NDArrayBacked" return type(self)._simple_new( - res_values, dtype=self.dtype, freq=new_freq # type: ignore[call-arg] + res_values, + dtype=self.dtype, + freq=new_freq, # type: ignore[call-arg] ) @final @@ -1256,7 +1258,9 @@ def _add_nat(self) -> Self: result = result.view(self._ndarray.dtype) # preserve reso # error: Unexpected keyword argument "freq" for "_simple_new" of "NDArrayBacked" return type(self)._simple_new( - result, dtype=self.dtype, freq=None # type: ignore[call-arg] + result, + dtype=self.dtype, + freq=None, # type: ignore[call-arg] ) @final @@ -2162,7 +2166,9 @@ def as_unit(self, unit: str, round_ok: bool = True) -> Self: # error: Unexpected keyword argument "freq" for "_simple_new" of # "NDArrayBacked" [call-arg] return type(self)._simple_new( - new_values, dtype=new_dtype, freq=self.freq # type: ignore[call-arg] + new_values, + dtype=new_dtype, + freq=self.freq, # type: ignore[call-arg] ) # TODO: annotate other as DatetimeArray | TimedeltaArray | Timestamp | Timedelta diff --git a/pandas/core/arrays/interval.py b/pandas/core/arrays/interval.py index febea079527e6..96ee728d6dcb7 100644 --- a/pandas/core/arrays/interval.py +++ b/pandas/core/arrays/interval.py @@ -122,9 +122,7 @@ } -_interval_shared_docs[ - "class" -] = """ +_interval_shared_docs["class"] = """ %(summary)s Parameters @@ -1489,9 +1487,7 @@ def set_closed(self, closed: IntervalClosedType) -> Self: dtype = IntervalDtype(left.dtype, closed=closed) return self._simple_new(left, right, dtype=dtype) - _interval_shared_docs[ - "is_non_overlapping_monotonic" - ] = """ + _interval_shared_docs["is_non_overlapping_monotonic"] = """ Return a boolean whether the %(klass)s is non-overlapping and monotonic. Non-overlapping means (no Intervals share points), and monotonic means diff --git a/pandas/core/arrays/masked.py b/pandas/core/arrays/masked.py index be7895fdb0275..9ce19ced2b356 100644 --- a/pandas/core/arrays/masked.py +++ b/pandas/core/arrays/masked.py @@ -1089,7 +1089,8 @@ def value_counts(self, dropna: bool = True) -> Series: arr = IntegerArray(value_counts, mask) index = Index( self.dtype.construct_array_type()( - keys, mask_index # type: ignore[arg-type] + keys, # type: ignore[arg-type] + mask_index, ) ) return Series(arr, index=index, name="count", copy=False) diff --git a/pandas/core/arrays/sparse/array.py b/pandas/core/arrays/sparse/array.py index b2d2e82c7a81f..fafeedc01b02b 100644 --- a/pandas/core/arrays/sparse/array.py +++ b/pandas/core/arrays/sparse/array.py @@ -454,7 +454,8 @@ def __init__( # error: Argument "dtype" to "asarray" has incompatible type # "Union[ExtensionDtype, dtype[Any], None]"; expected "None" sparse_values = np.asarray( - data.sp_values, dtype=dtype # type: ignore[arg-type] + data.sp_values, + dtype=dtype, # type: ignore[arg-type] ) elif sparse_index is None: data = extract_array(data, extract_numpy=True) diff --git a/pandas/core/base.py b/pandas/core/base.py index e98f1157572bb..490daa656f603 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -1207,9 +1207,7 @@ def factorize( uniques = Index(uniques) return codes, uniques - _shared_docs[ - "searchsorted" - ] = """ + _shared_docs["searchsorted"] = """ Find indices where elements should be inserted to maintain order. Find the indices into a sorted {klass} `self` such that, if the diff --git a/pandas/core/computation/expr.py b/pandas/core/computation/expr.py index b5861fbaebe9c..f0aa7363d2644 100644 --- a/pandas/core/computation/expr.py +++ b/pandas/core/computation/expr.py @@ -695,8 +695,7 @@ def visit_Call(self, node, side=None, **kwargs): if not isinstance(key, ast.keyword): # error: "expr" has no attribute "id" raise ValueError( - "keyword error in function call " - f"'{node.func.id}'" # type: ignore[attr-defined] + "keyword error in function call " f"'{node.func.id}'" # type: ignore[attr-defined] ) if key.arg: diff --git a/pandas/core/dtypes/cast.py b/pandas/core/dtypes/cast.py index 9a1ec2330a326..5a0867d0251e8 100644 --- a/pandas/core/dtypes/cast.py +++ b/pandas/core/dtypes/cast.py @@ -589,7 +589,9 @@ def maybe_promote(dtype: np.dtype, fill_value=np.nan): # error: Argument 3 to "__call__" of "_lru_cache_wrapper" has incompatible type # "Type[Any]"; expected "Hashable" [arg-type] dtype, fill_value = _maybe_promote_cached( - dtype, fill_value, type(fill_value) # type: ignore[arg-type] + dtype, + fill_value, + type(fill_value), # type: ignore[arg-type] ) except TypeError: # if fill_value is not hashable (required for caching) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 73b5804d8c168..6851955d693bc 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -1405,9 +1405,7 @@ def style(self) -> Styler: return Styler(self) - _shared_docs[ - "items" - ] = r""" + _shared_docs["items"] = r""" Iterate over (column name, Series) pairs. Iterates over the DataFrame columns, returning a tuple with @@ -2030,8 +2028,7 @@ def to_dict( orient: Literal[ "dict", "list", "series", "split", "tight", "records", "index" ] = "dict", - into: type[MutableMappingT] - | MutableMappingT = dict, # type: ignore[assignment] + into: type[MutableMappingT] | MutableMappingT = dict, # type: ignore[assignment] index: bool = True, ) -> MutableMappingT | list[MutableMappingT]: """ @@ -9137,9 +9134,7 @@ def groupby( dropna=dropna, ) - _shared_docs[ - "pivot" - ] = """ + _shared_docs["pivot"] = """ Return reshaped DataFrame organized by given index / column values. Reshape data (produce a "pivot" table) based on column values. Uses @@ -9283,9 +9278,7 @@ def pivot( return pivot(self, index=index, columns=columns, values=values) - _shared_docs[ - "pivot_table" - ] = """ + _shared_docs["pivot_table"] = """ Create a spreadsheet-style pivot table as a DataFrame. The levels in the pivot table will be stored in MultiIndex objects @@ -12529,7 +12522,7 @@ def _to_dict_of_blocks(self): mgr = cast(BlockManager, mgr_to_mgr(mgr, "block")) return { k: self._constructor_from_mgr(v, axes=v.axes).__finalize__(self) - for k, v, in mgr.to_dict().items() + for k, v in mgr.to_dict().items() } @property diff --git a/pandas/core/generic.py b/pandas/core/generic.py index c06703660f82d..b37f22339fcfd 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -8006,8 +8006,6 @@ def replace( if items: keys, values = zip(*items) else: - # error: Incompatible types in assignment (expression has type - # "list[Never]", variable has type "tuple[Any, ...]") keys, values = ([], []) # type: ignore[assignment] are_mappings = [is_dict_like(v) for v in values] @@ -8825,15 +8823,11 @@ def _clip_with_scalar(self, lower, upper, inplace: bool_t = False): if lower is not None: cond = mask | (self >= lower) - result = result.where( - cond, lower, inplace=inplace - ) # type: ignore[assignment] + result = result.where(cond, lower, inplace=inplace) # type: ignore[assignment] if upper is not None: cond = mask | (self <= upper) result = self if inplace else result - result = result.where( - cond, upper, inplace=inplace - ) # type: ignore[assignment] + result = result.where(cond, upper, inplace=inplace) # type: ignore[assignment] return result @@ -12242,7 +12236,12 @@ def _accum_func( if axis == 1: return self.T._accum_func( - name, func, axis=0, skipna=skipna, *args, **kwargs # noqa: B026 + name, + func, + axis=0, + skipna=skipna, + *args, # noqa: B026 + **kwargs, ).T def block_accum_func(blk_values): @@ -12720,14 +12719,16 @@ def __imul__(self, other) -> Self: def __itruediv__(self, other) -> Self: # error: Unsupported left operand type for / ("Type[NDFrame]") return self._inplace_method( - other, type(self).__truediv__ # type: ignore[operator] + other, + type(self).__truediv__, # type: ignore[operator] ) @final def __ifloordiv__(self, other) -> Self: # error: Unsupported left operand type for // ("Type[NDFrame]") return self._inplace_method( - other, type(self).__floordiv__ # type: ignore[operator] + other, + type(self).__floordiv__, # type: ignore[operator] ) @final @@ -13495,9 +13496,7 @@ def last_valid_index(self) -> Hashable | None: Series([], dtype: bool) """ -_shared_docs[ - "stat_func_example" -] = """ +_shared_docs["stat_func_example"] = """ Examples -------- diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index f2e314046fb74..9598bc0db02cc 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -848,7 +848,10 @@ def value_counts( # "List[ndarray[Any, Any]]"; expected "List[Union[Union[ExtensionArray, # ndarray[Any, Any]], Index, Series]] _, idx = get_join_indexers( - left, right, sort=False, how="left" # type: ignore[arg-type] + left, # type: ignore[arg-type] + right, # type: ignore[arg-type] + sort=False, + how="left", ) if idx is not None: out = np.where(idx != -1, out[idx], 0) diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index 089e15afd465b..c9beaee55d608 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -5187,7 +5187,10 @@ def shift( period = cast(int, period) if freq is not None or axis != 0: f = lambda x: x.shift( - period, freq, axis, fill_value # pylint: disable=cell-var-from-loop + period, # pylint: disable=cell-var-from-loop + freq, + axis, + fill_value, ) shifted = self._python_apply_general( f, self._selected_obj, is_transform=True diff --git a/pandas/core/groupby/grouper.py b/pandas/core/groupby/grouper.py index e2224caad9e84..e68c393f8f707 100644 --- a/pandas/core/groupby/grouper.py +++ b/pandas/core/groupby/grouper.py @@ -1008,7 +1008,8 @@ def is_in_obj(gpr) -> bool: return False if isinstance(gpr, Series) and isinstance(obj_gpr_column, Series): return gpr._mgr.references_same_values( # type: ignore[union-attr] - obj_gpr_column._mgr, 0 # type: ignore[arg-type] + obj_gpr_column._mgr, # type: ignore[arg-type] + 0, ) return False try: diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 166d6946beacf..74c1f165ac06c 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1107,9 +1107,7 @@ def astype(self, dtype, copy: bool = True): result._references.add_index_reference(result) return result - _index_shared_docs[ - "take" - ] = """ + _index_shared_docs["take"] = """ Return a new %(klass)s of the values selected by the indices. For internal compatibility with numpy arrays. @@ -1196,9 +1194,7 @@ def _maybe_disallow_fill(self, allow_fill: bool, fill_value, indices) -> bool: allow_fill = False return allow_fill - _index_shared_docs[ - "repeat" - ] = """ + _index_shared_docs["repeat"] = """ Repeat elements of a %(klass)s. Returns a new %(klass)s where each element of the current %(klass)s @@ -5807,7 +5803,8 @@ def asof_locs( # types "Union[ExtensionArray, ndarray[Any, Any]]", "str" # TODO: will be fixed when ExtensionArray.searchsorted() is fixed locs = self._values[mask].searchsorted( - where._values, side="right" # type: ignore[call-overload] + where._values, + side="right", # type: ignore[call-overload] ) locs = np.where(locs > 0, locs - 1, 0) @@ -6069,9 +6066,7 @@ def _should_fallback_to_positional(self) -> bool: "complex", } - _index_shared_docs[ - "get_indexer_non_unique" - ] = """ + _index_shared_docs["get_indexer_non_unique"] = """ Compute indexer and mask for new index given the current index. The indexer should be then used as an input to ndarray.take to align the diff --git a/pandas/core/indexes/interval.py b/pandas/core/indexes/interval.py index 4fcdb87974511..b62c19bef74be 100644 --- a/pandas/core/indexes/interval.py +++ b/pandas/core/indexes/interval.py @@ -555,9 +555,7 @@ def _maybe_convert_i8(self, key): right = self._maybe_convert_i8(key.right) constructor = Interval if scalar else IntervalIndex.from_arrays # error: "object" not callable - return constructor( - left, right, closed=self.closed - ) # type: ignore[operator] + return constructor(left, right, closed=self.closed) # type: ignore[operator] if scalar: # Timestamp/Timedelta diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index 1352238eb60ec..5242706e0ce23 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -2673,7 +2673,8 @@ def sortlevel( # error: Item "Hashable" of "Union[Hashable, Sequence[Hashable]]" has # no attribute "__iter__" (not iterable) level = [ - self._get_level_number(lev) for lev in level # type: ignore[union-attr] + self._get_level_number(lev) + for lev in level # type: ignore[union-attr] ] sortorder = None @@ -4056,8 +4057,6 @@ def sparsify_labels(label_list, start: int = 0, sentinel: object = ""): for i, (p, t) in enumerate(zip(prev, cur)): if i == k - 1: sparse_cur.append(t) - # error: Argument 1 to "append" of "list" has incompatible - # type "list[Any]"; expected "tuple[Any, ...]" result.append(sparse_cur) # type: ignore[arg-type] break @@ -4065,8 +4064,6 @@ def sparsify_labels(label_list, start: int = 0, sentinel: object = ""): sparse_cur.append(sentinel) else: sparse_cur.extend(cur[i:]) - # error: Argument 1 to "append" of "list" has incompatible - # type "list[Any]"; expected "tuple[Any, ...]" result.append(sparse_cur) # type: ignore[arg-type] break diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index 06fd9ebe47eae..8a54cb2d7a189 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -1843,7 +1843,8 @@ def shift(self, periods: int, fill_value: Any = None) -> list[Block]: # error: Argument 1 to "np_can_hold_element" has incompatible type # "Union[dtype[Any], ExtensionDtype]"; expected "dtype[Any]" casted = np_can_hold_element( - self.dtype, fill_value # type: ignore[arg-type] + self.dtype, # type: ignore[arg-type] + fill_value, ) except LossySetitemError: nb = self.coerce_to_target_dtype(fill_value) diff --git a/pandas/core/internals/concat.py b/pandas/core/internals/concat.py index b2d463a8c6c26..4445627732a9b 100644 --- a/pandas/core/internals/concat.py +++ b/pandas/core/internals/concat.py @@ -118,7 +118,9 @@ def concatenate_managers( # type "List[BlockManager]"; expected "List[Union[ArrayManager, # SingleArrayManager, BlockManager, SingleBlockManager]]" return _concatenate_array_managers( - mgrs, axes, concat_axis # type: ignore[arg-type] + mgrs, # type: ignore[arg-type] + axes, + concat_axis, ) # Assertions disabled for performance @@ -474,9 +476,7 @@ def _concatenate_join_units(join_units: list[JoinUnit], copy: bool) -> ArrayLike # error: No overload variant of "__getitem__" of "ExtensionArray" matches # argument type "Tuple[int, slice]" to_concat = [ - t - if is_1d_only_ea_dtype(t.dtype) - else t[0, :] # type: ignore[call-overload] + t if is_1d_only_ea_dtype(t.dtype) else t[0, :] # type: ignore[call-overload] for t in to_concat ] concat_values = concat_compat(to_concat, axis=0, ea_compat_axis=True) diff --git a/pandas/core/reshape/pivot.py b/pandas/core/reshape/pivot.py index b2a915589cba7..ea74c17917279 100644 --- a/pandas/core/reshape/pivot.py +++ b/pandas/core/reshape/pivot.py @@ -535,7 +535,8 @@ def pivot( # error: Unsupported operand types for + ("List[Any]" and "ExtensionArray") # error: Unsupported left operand type for + ("ExtensionArray") indexed = data.set_index( - cols + columns_listlike, append=append # type: ignore[operator] + cols + columns_listlike, # type: ignore[operator] + append=append, ) else: index_list: list[Index] | list[Series] diff --git a/pandas/core/series.py b/pandas/core/series.py index 487f57b7390a8..1f9ac8511476e 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2023,8 +2023,7 @@ def to_dict(self, *, into: type[dict] = ...) -> dict: ) def to_dict( self, - into: type[MutableMappingT] - | MutableMappingT = dict, # type: ignore[assignment] + into: type[MutableMappingT] | MutableMappingT = dict, # type: ignore[assignment] ) -> MutableMappingT: """ Convert Series to {label -> value} dict or dict-like object. diff --git a/pandas/core/shared_docs.py b/pandas/core/shared_docs.py index 25f7e7e9f832b..3369df5da4cba 100644 --- a/pandas/core/shared_docs.py +++ b/pandas/core/shared_docs.py @@ -2,9 +2,7 @@ _shared_docs: dict[str, str] = {} -_shared_docs[ - "aggregate" -] = """ +_shared_docs["aggregate"] = """ Aggregate using one or more operations over the specified axis. Parameters @@ -53,9 +51,7 @@ A passed user-defined-function will be passed a Series for evaluation. {examples}""" -_shared_docs[ - "compare" -] = """ +_shared_docs["compare"] = """ Compare to another {klass} and show the differences. Parameters @@ -85,9 +81,7 @@ .. versionadded:: 1.5.0 """ -_shared_docs[ - "groupby" -] = """ +_shared_docs["groupby"] = """ Group %(klass)s using a mapper or by a Series of columns. A groupby operation involves some combination of splitting the @@ -195,9 +189,7 @@ iterating through groups, selecting a group, aggregation, and more. """ -_shared_docs[ - "melt" -] = """ +_shared_docs["melt"] = """ Unpivot a DataFrame from wide to long format, optionally leaving identifiers set. This function is useful to massage a DataFrame into a format where one @@ -311,9 +303,7 @@ 2 c B E 5 """ -_shared_docs[ - "transform" -] = """ +_shared_docs["transform"] = """ Call ``func`` on self producing a {klass} with the same axis shape as self. Parameters @@ -438,9 +428,7 @@ 6 2 n 4 """ -_shared_docs[ - "storage_options" -] = """storage_options : dict, optional +_shared_docs["storage_options"] = """storage_options : dict, optional Extra options that make sense for a particular storage connection, e.g. host, port, username, password, etc. For HTTP(S) URLs the key-value pairs are forwarded to ``urllib.request.Request`` as header options. For other @@ -450,9 +438,7 @@ `_.""" -_shared_docs[ - "compression_options" -] = """compression : str or dict, default 'infer' +_shared_docs["compression_options"] = """compression : str or dict, default 'infer' For on-the-fly compression of the output data. If 'infer' and '%s' is path-like, then detect compression from the following extensions: '.gz', '.bz2', '.zip', '.xz', '.zst', '.tar', '.tar.gz', '.tar.xz' or '.tar.bz2' @@ -471,9 +457,7 @@ .. versionadded:: 1.5.0 Added support for `.tar` files.""" -_shared_docs[ - "decompression_options" -] = """compression : str or dict, default 'infer' +_shared_docs["decompression_options"] = """compression : str or dict, default 'infer' For on-the-fly decompression of on-disk data. If 'infer' and '%s' is path-like, then detect compression from the following extensions: '.gz', '.bz2', '.zip', '.xz', '.zst', '.tar', '.tar.gz', '.tar.xz' or '.tar.bz2' @@ -493,9 +477,7 @@ .. versionadded:: 1.5.0 Added support for `.tar` files.""" -_shared_docs[ - "replace" -] = """ +_shared_docs["replace"] = """ Replace values given in `to_replace` with `value`. Values of the {klass} are replaced with other values dynamically. @@ -817,9 +799,7 @@ 4 4 e e """ -_shared_docs[ - "idxmin" -] = """ +_shared_docs["idxmin"] = """ Return index of first occurrence of minimum over requested axis. NA/null values are excluded. @@ -884,9 +864,7 @@ dtype: object """ -_shared_docs[ - "idxmax" -] = """ +_shared_docs["idxmax"] = """ Return index of first occurrence of maximum over requested axis. NA/null values are excluded. diff --git a/pandas/core/strings/accessor.py b/pandas/core/strings/accessor.py index 1b7d632c0fa80..7c6dca3bad7d9 100644 --- a/pandas/core/strings/accessor.py +++ b/pandas/core/strings/accessor.py @@ -707,9 +707,7 @@ def cat( out = res_ser.__finalize__(self._orig, method="str_cat") return out - _shared_docs[ - "str_split" - ] = r""" + _shared_docs["str_split"] = r""" Split strings around given separator/delimiter. Splits the string in the Series/Index from the %(side)s, @@ -946,9 +944,7 @@ def rsplit(self, pat=None, *, n=-1, expand: bool = False): result, expand=expand, returns_string=expand, dtype=dtype ) - _shared_docs[ - "str_partition" - ] = """ + _shared_docs["str_partition"] = """ Split the string at the %(side)s occurrence of `sep`. This method splits the string at the %(side)s occurrence of `sep`, @@ -1686,9 +1682,7 @@ def pad( result = self._data.array._str_pad(width, side=side, fillchar=fillchar) return self._wrap_result(result) - _shared_docs[ - "str_pad" - ] = """ + _shared_docs["str_pad"] = """ Pad %(side)s side of strings in the Series/Index. Equivalent to :meth:`str.%(method)s`. @@ -2036,9 +2030,7 @@ def encode(self, encoding, errors: str = "strict"): result = self._data.array._str_encode(encoding, errors) return self._wrap_result(result, returns_string=False) - _shared_docs[ - "str_strip" - ] = r""" + _shared_docs["str_strip"] = r""" Remove %(position)s characters. Strip whitespaces (including newlines) or a set of specified characters @@ -2143,9 +2135,7 @@ def rstrip(self, to_strip=None): result = self._data.array._str_rstrip(to_strip) return self._wrap_result(result) - _shared_docs[ - "str_removefix" - ] = r""" + _shared_docs["str_removefix"] = r""" Remove a %(side)s from an object series. If the %(side)s is not present, the original string will be returned. @@ -2852,9 +2842,7 @@ def extractall(self, pat, flags: int = 0) -> DataFrame: # TODO: dispatch return str_extractall(self._orig, pat, flags) - _shared_docs[ - "find" - ] = """ + _shared_docs["find"] = """ Return %(side)s indexes in each strings in the Series/Index. Each of returned indexes corresponds to the position where the @@ -2960,9 +2948,7 @@ def normalize(self, form): result = self._data.array._str_normalize(form) return self._wrap_result(result) - _shared_docs[ - "index" - ] = """ + _shared_docs["index"] = """ Return %(side)s indexes in each string in Series/Index. Each of the returned indexes corresponds to the position where the @@ -3094,9 +3080,7 @@ def len(self): result = self._data.array._str_len() return self._wrap_result(result, returns_string=False) - _shared_docs[ - "casemethods" - ] = """ + _shared_docs["casemethods"] = """ Convert strings in the Series/Index to %(type)s. %(version)s Equivalent to :meth:`str.%(method)s`. @@ -3224,9 +3208,7 @@ def casefold(self): result = self._data.array._str_casefold() return self._wrap_result(result) - _shared_docs[ - "ismethods" - ] = """ + _shared_docs["ismethods"] = """ Check whether all characters in each string are %(type)s. This is equivalent to running the Python string method diff --git a/pandas/io/common.py b/pandas/io/common.py index 57bc6c1379d77..576bf7215f363 100644 --- a/pandas/io/common.py +++ b/pandas/io/common.py @@ -792,7 +792,9 @@ def get_handle( # "Union[str, BaseBuffer]"; expected "Union[Union[str, PathLike[str]], # ReadBuffer[bytes], WriteBuffer[bytes]]" handle = _BytesZipFile( - handle, ioargs.mode, **compression_args # type: ignore[arg-type] + handle, # type: ignore[arg-type] + ioargs.mode, + **compression_args, ) if handle.buffer.mode == "r": handles.append(handle) @@ -817,7 +819,8 @@ def get_handle( # type "BaseBuffer"; expected "Union[ReadBuffer[bytes], # WriteBuffer[bytes], None]" handle = _BytesTarFile( - fileobj=handle, **compression_args # type: ignore[arg-type] + fileobj=handle, # type: ignore[arg-type] + **compression_args, ) assert isinstance(handle, _BytesTarFile) if "r" in handle.buffer.mode: @@ -841,7 +844,9 @@ def get_handle( # BaseBuffer]"; expected "Optional[Union[Union[str, bytes, PathLike[str], # PathLike[bytes]], IO[bytes]], None]" handle = get_lzma_file()( - handle, ioargs.mode, **compression_args # type: ignore[arg-type] + handle, # type: ignore[arg-type] + ioargs.mode, + **compression_args, ) # Zstd Compression @@ -1137,7 +1142,9 @@ def _maybe_memory_map( # expected "BaseBuffer" wrapped = _IOWrapper( mmap.mmap( - handle.fileno(), 0, access=mmap.ACCESS_READ # type: ignore[arg-type] + handle.fileno(), + 0, + access=mmap.ACCESS_READ, # type: ignore[arg-type] ) ) finally: diff --git a/pandas/io/excel/_calamine.py b/pandas/io/excel/_calamine.py index 4f65acf1aa40e..1f721c65982d4 100644 --- a/pandas/io/excel/_calamine.py +++ b/pandas/io/excel/_calamine.py @@ -75,7 +75,8 @@ def load_workbook( from python_calamine import load_workbook return load_workbook( - filepath_or_buffer, **engine_kwargs # type: ignore[arg-type] + filepath_or_buffer, # type: ignore[arg-type] + **engine_kwargs, ) @property diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index c30238e412450..36c9b66f2bd47 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -2170,9 +2170,7 @@ def convert( # "Union[Type[Index], Type[DatetimeIndex]]") factory = lambda x, **kwds: PeriodIndex.from_ordinals( # type: ignore[assignment] x, freq=kwds.get("freq", None) - )._rename( - kwds["name"] - ) + )._rename(kwds["name"]) # making an Index instance could throw a number of different errors try: @@ -3181,7 +3179,9 @@ def write_array( # error: Item "ExtensionArray" of "Union[Any, ExtensionArray]" has no # attribute "asi8" self._handle.create_array( - self.group, key, value.asi8 # type: ignore[union-attr] + self.group, + key, + value.asi8, # type: ignore[union-attr] ) node = getattr(self.group, key) diff --git a/pandas/plotting/_matplotlib/core.py b/pandas/plotting/_matplotlib/core.py index 2979903edf360..136056e3ff428 100644 --- a/pandas/plotting/_matplotlib/core.py +++ b/pandas/plotting/_matplotlib/core.py @@ -616,8 +616,7 @@ def result(self): # error: Argument 1 to "len" has incompatible type "Union[bool, # Tuple[Any, ...], List[Any], ndarray[Any, Any]]"; expected "Sized" all_sec = ( - is_list_like(self.secondary_y) - and len(self.secondary_y) == self.nseries # type: ignore[arg-type] + is_list_like(self.secondary_y) and len(self.secondary_y) == self.nseries # type: ignore[arg-type] ) if sec_true or all_sec: # if all data is plotted on secondary, return right axes diff --git a/pandas/plotting/_matplotlib/hist.py b/pandas/plotting/_matplotlib/hist.py index 898abc9b78e3f..ab2dc20ccbd02 100644 --- a/pandas/plotting/_matplotlib/hist.py +++ b/pandas/plotting/_matplotlib/hist.py @@ -202,17 +202,13 @@ def _post_plot_logic(self, ax: Axes, data) -> None: # error: Argument 1 to "set_xlabel" of "_AxesBase" has incompatible # type "Hashable"; expected "str" ax.set_xlabel( - "Frequency" - if self.xlabel is None - else self.xlabel # type: ignore[arg-type] + "Frequency" if self.xlabel is None else self.xlabel # type: ignore[arg-type] ) ax.set_ylabel(self.ylabel) # type: ignore[arg-type] else: ax.set_xlabel(self.xlabel) # type: ignore[arg-type] ax.set_ylabel( - "Frequency" - if self.ylabel is None - else self.ylabel # type: ignore[arg-type] + "Frequency" if self.ylabel is None else self.ylabel # type: ignore[arg-type] ) @property diff --git a/pandas/plotting/_matplotlib/timeseries.py b/pandas/plotting/_matplotlib/timeseries.py index bf1c0f6346f02..067bcf0b01ccb 100644 --- a/pandas/plotting/_matplotlib/timeseries.py +++ b/pandas/plotting/_matplotlib/timeseries.py @@ -250,9 +250,7 @@ def use_dynamic_x(ax: Axes, data: DataFrame | Series) -> bool: if isinstance(data.index, ABCDatetimeIndex): # error: "BaseOffset" has no attribute "_period_dtype_code" freq_str = OFFSET_TO_PERIOD_FREQSTR.get(freq_str, freq_str) - base = to_offset( - freq_str, is_period=True - )._period_dtype_code # type: ignore[attr-defined] + base = to_offset(freq_str, is_period=True)._period_dtype_code # type: ignore[attr-defined] x = data.index if base <= FreqGroup.FR_DAY.value: return x[:1].is_normalized diff --git a/pandas/tests/dtypes/test_inference.py b/pandas/tests/dtypes/test_inference.py index 475473218f712..5eeab778c184c 100644 --- a/pandas/tests/dtypes/test_inference.py +++ b/pandas/tests/dtypes/test_inference.py @@ -656,9 +656,7 @@ def test_convert_numeric_uint64_nan_values( arr = np.array([2**63, 2**63 + 1], dtype=object) na_values = {2**63} - expected = ( - np.array([np.nan, 2**63 + 1], dtype=float) if coerce else arr.copy() - ) + expected = np.array([np.nan, 2**63 + 1], dtype=float) if coerce else arr.copy() result = lib.maybe_convert_numeric( arr, na_values, diff --git a/pandas/tests/dtypes/test_missing.py b/pandas/tests/dtypes/test_missing.py index e1f8d8eca2537..7105755df6f88 100644 --- a/pandas/tests/dtypes/test_missing.py +++ b/pandas/tests/dtypes/test_missing.py @@ -843,7 +843,8 @@ def test_empty_like(self): class TestLibMissing: @pytest.mark.parametrize("func", [libmissing.checknull, isna]) @pytest.mark.parametrize( - "value", na_vals + sometimes_na_vals # type: ignore[operator] + "value", + na_vals + sometimes_na_vals, # type: ignore[operator] ) def test_checknull_na_vals(self, func, value): assert func(value) @@ -864,7 +865,8 @@ def test_checknull_never_na_vals(self, func, value): assert not func(value) @pytest.mark.parametrize( - "value", na_vals + sometimes_na_vals # type: ignore[operator] + "value", + na_vals + sometimes_na_vals, # type: ignore[operator] ) def test_checknull_old_na_vals(self, value): assert libmissing.checknull(value, inf_as_na=True) diff --git a/pandas/tests/frame/methods/test_first_and_last.py b/pandas/tests/frame/methods/test_first_and_last.py index 212e56442ee07..2170cf254fbe6 100644 --- a/pandas/tests/frame/methods/test_first_and_last.py +++ b/pandas/tests/frame/methods/test_first_and_last.py @@ -61,17 +61,13 @@ def test_first_last_raises(self, frame_or_series): msg = "'first' only supports a DatetimeIndex index" with tm.assert_produces_warning( FutureWarning, match=deprecated_msg - ), pytest.raises( - TypeError, match=msg - ): # index is not a DatetimeIndex + ), pytest.raises(TypeError, match=msg): # index is not a DatetimeIndex obj.first("1D") msg = "'last' only supports a DatetimeIndex index" with tm.assert_produces_warning( FutureWarning, match=last_deprecated_msg - ), pytest.raises( - TypeError, match=msg - ): # index is not a DatetimeIndex + ), pytest.raises(TypeError, match=msg): # index is not a DatetimeIndex obj.last("1D") def test_last_subset(self, frame_or_series): diff --git a/pandas/tests/frame/methods/test_rank.py b/pandas/tests/frame/methods/test_rank.py index 1d0931f5982b7..79aabbcc83bbf 100644 --- a/pandas/tests/frame/methods/test_rank.py +++ b/pandas/tests/frame/methods/test_rank.py @@ -319,9 +319,7 @@ def test_rank_pct_true(self, rank_method, exp): @pytest.mark.single_cpu def test_pct_max_many_rows(self): # GH 18271 - df = DataFrame( - {"A": np.arange(2**24 + 1), "B": np.arange(2**24 + 1, 0, -1)} - ) + df = DataFrame({"A": np.arange(2**24 + 1), "B": np.arange(2**24 + 1, 0, -1)}) result = df.rank(pct=True).max() assert (result == 1).all() diff --git a/pandas/tests/frame/methods/test_reset_index.py b/pandas/tests/frame/methods/test_reset_index.py index fbf36dbc4fb02..9d07b8ab2288f 100644 --- a/pandas/tests/frame/methods/test_reset_index.py +++ b/pandas/tests/frame/methods/test_reset_index.py @@ -232,9 +232,7 @@ def test_reset_index_level_missing(self, idx_lev): def test_reset_index_right_dtype(self): time = np.arange(0.0, 10, np.sqrt(2) / 2) - s1 = Series( - (9.81 * time**2) / 2, index=Index(time, name="time"), name="speed" - ) + s1 = Series((9.81 * time**2) / 2, index=Index(time, name="time"), name="speed") df = DataFrame(s1) reset = s1.reset_index() diff --git a/pandas/tests/groupby/aggregate/test_aggregate.py b/pandas/tests/groupby/aggregate/test_aggregate.py index 6223a153df358..5a69c26f2ab16 100644 --- a/pandas/tests/groupby/aggregate/test_aggregate.py +++ b/pandas/tests/groupby/aggregate/test_aggregate.py @@ -1188,9 +1188,7 @@ def test_agg_with_one_lambda(self): # check pd.NameAgg case result1 = df.groupby(by="kind").agg( - height_sqr_min=pd.NamedAgg( - column="height", aggfunc=lambda x: np.min(x**2) - ), + height_sqr_min=pd.NamedAgg(column="height", aggfunc=lambda x: np.min(x**2)), height_max=pd.NamedAgg(column="height", aggfunc="max"), weight_max=pd.NamedAgg(column="weight", aggfunc="max"), ) @@ -1245,9 +1243,7 @@ def test_agg_multiple_lambda(self): # check pd.NamedAgg case result2 = df.groupby(by="kind").agg( - height_sqr_min=pd.NamedAgg( - column="height", aggfunc=lambda x: np.min(x**2) - ), + height_sqr_min=pd.NamedAgg(column="height", aggfunc=lambda x: np.min(x**2)), height_max=pd.NamedAgg(column="height", aggfunc="max"), weight_max=pd.NamedAgg(column="weight", aggfunc="max"), height_max_2=pd.NamedAgg(column="height", aggfunc=lambda x: np.max(x)), diff --git a/pandas/tests/indexes/datetimes/test_scalar_compat.py b/pandas/tests/indexes/datetimes/test_scalar_compat.py index e93fc0e2a4e2e..f766894a993a0 100644 --- a/pandas/tests/indexes/datetimes/test_scalar_compat.py +++ b/pandas/tests/indexes/datetimes/test_scalar_compat.py @@ -135,7 +135,8 @@ def test_dti_hour_tzaware(self, prefix): # GH#12806 # error: Unsupported operand types for + ("List[None]" and "List[str]") @pytest.mark.parametrize( - "time_locale", [None] + tm.get_locales() # type: ignore[operator] + "time_locale", + [None] + tm.get_locales(), # type: ignore[operator] ) def test_day_name_month_name(self, time_locale): # Test Monday -> Sunday and January -> December, in that sequence diff --git a/pandas/tests/indexes/multi/test_sorting.py b/pandas/tests/indexes/multi/test_sorting.py index b4dcef71dcf50..4a1a6b9c452d5 100644 --- a/pandas/tests/indexes/multi/test_sorting.py +++ b/pandas/tests/indexes/multi/test_sorting.py @@ -151,7 +151,7 @@ def test_unsortedindex_doc_examples(): msg = r"Key length \(2\) was greater than MultiIndex lexsort depth \(1\)" with pytest.raises(UnsortedIndexError, match=msg): - dfm.loc[(0, "y"):(1, "z")] + dfm.loc[(0, "y") : (1, "z")] assert not dfm.index._is_lexsorted() assert dfm.index._lexsort_depth == 1 @@ -159,7 +159,7 @@ def test_unsortedindex_doc_examples(): # sort it dfm = dfm.sort_index() dfm.loc[(1, "z")] - dfm.loc[(0, "y"):(1, "z")] + dfm.loc[(0, "y") : (1, "z")] assert dfm.index._is_lexsorted() assert dfm.index._lexsort_depth == 2 diff --git a/pandas/tests/indexes/numeric/test_indexing.py b/pandas/tests/indexes/numeric/test_indexing.py index f2458a6c6114d..29f8a0a5a5932 100644 --- a/pandas/tests/indexes/numeric/test_indexing.py +++ b/pandas/tests/indexes/numeric/test_indexing.py @@ -403,8 +403,9 @@ def test_get_indexer_arrow_dictionary_target(self): tm.assert_numpy_array_equal(result, expected) result_1, result_2 = idx.get_indexer_non_unique(target) - expected_1, expected_2 = np.array([0, -1], dtype=np.int64), np.array( - [1], dtype=np.int64 + expected_1, expected_2 = ( + np.array([0, -1], dtype=np.int64), + np.array([1], dtype=np.int64), ) tm.assert_numpy_array_equal(result_1, expected_1) tm.assert_numpy_array_equal(result_2, expected_2) diff --git a/pandas/tests/indexes/numeric/test_join.py b/pandas/tests/indexes/numeric/test_join.py index 918d505216735..9839f40861d55 100644 --- a/pandas/tests/indexes/numeric/test_join.py +++ b/pandas/tests/indexes/numeric/test_join.py @@ -313,15 +313,11 @@ def test_join_right(self, index_large): tm.assert_numpy_array_equal(ridx, eridx) def test_join_non_int_index(self, index_large): - other = Index( - 2**63 + np.array([1, 5, 7, 10, 20], dtype="uint64"), dtype=object - ) + other = Index(2**63 + np.array([1, 5, 7, 10, 20], dtype="uint64"), dtype=object) outer = index_large.join(other, how="outer") outer2 = other.join(index_large, how="outer") - expected = Index( - 2**63 + np.array([0, 1, 5, 7, 10, 15, 20, 25], dtype="uint64") - ) + expected = Index(2**63 + np.array([0, 1, 5, 7, 10, 15, 20, 25], dtype="uint64")) tm.assert_index_equal(outer, outer2) tm.assert_index_equal(outer, expected) @@ -353,9 +349,7 @@ def test_join_outer(self, index_large): noidx_res = index_large.join(other, how="outer") tm.assert_index_equal(res, noidx_res) - eres = Index( - 2**63 + np.array([0, 1, 2, 7, 10, 12, 15, 20, 25], dtype="uint64") - ) + eres = Index(2**63 + np.array([0, 1, 2, 7, 10, 12, 15, 20, 25], dtype="uint64")) elidx = np.array([0, -1, -1, -1, 1, -1, 2, 3, 4], dtype=np.intp) eridx = np.array([-1, 3, 4, 0, 5, 1, -1, -1, 2], dtype=np.intp) diff --git a/pandas/tests/indexing/multiindex/test_partial.py b/pandas/tests/indexing/multiindex/test_partial.py index 5aff1f1309004..830c187a205a8 100644 --- a/pandas/tests/indexing/multiindex/test_partial.py +++ b/pandas/tests/indexing/multiindex/test_partial.py @@ -93,7 +93,7 @@ def test_fancy_slice_partial( tm.assert_frame_equal(result, expected) ymd = multiindex_year_month_day_dataframe_random_data - result = ymd.loc[(2000, 2):(2000, 4)] + result = ymd.loc[(2000, 2) : (2000, 4)] lev = ymd.index.codes[1] expected = ymd[(lev >= 1) & (lev <= 3)] tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/indexing/multiindex/test_slice.py b/pandas/tests/indexing/multiindex/test_slice.py index cef3dca054758..7f298e9bdd375 100644 --- a/pandas/tests/indexing/multiindex/test_slice.py +++ b/pandas/tests/indexing/multiindex/test_slice.py @@ -700,21 +700,23 @@ def test_multiindex_label_slicing_with_negative_step(self): tm.assert_indexing_slices_equivalent(ser, SLC[::-1], SLC[::-1]) tm.assert_indexing_slices_equivalent(ser, SLC["d"::-1], SLC[15::-1]) - tm.assert_indexing_slices_equivalent(ser, SLC[("d",)::-1], SLC[15::-1]) + tm.assert_indexing_slices_equivalent(ser, SLC[("d",) :: -1], SLC[15::-1]) tm.assert_indexing_slices_equivalent(ser, SLC[:"d":-1], SLC[:11:-1]) - tm.assert_indexing_slices_equivalent(ser, SLC[:("d",):-1], SLC[:11:-1]) + tm.assert_indexing_slices_equivalent(ser, SLC[: ("d",) : -1], SLC[:11:-1]) tm.assert_indexing_slices_equivalent(ser, SLC["d":"b":-1], SLC[15:3:-1]) - tm.assert_indexing_slices_equivalent(ser, SLC[("d",):"b":-1], SLC[15:3:-1]) - tm.assert_indexing_slices_equivalent(ser, SLC["d":("b",):-1], SLC[15:3:-1]) - tm.assert_indexing_slices_equivalent(ser, SLC[("d",):("b",):-1], SLC[15:3:-1]) + tm.assert_indexing_slices_equivalent(ser, SLC[("d",) : "b" : -1], SLC[15:3:-1]) + tm.assert_indexing_slices_equivalent(ser, SLC["d" : ("b",) : -1], SLC[15:3:-1]) + tm.assert_indexing_slices_equivalent( + ser, SLC[("d",) : ("b",) : -1], SLC[15:3:-1] + ) tm.assert_indexing_slices_equivalent(ser, SLC["b":"d":-1], SLC[:0]) - tm.assert_indexing_slices_equivalent(ser, SLC[("c", 2)::-1], SLC[10::-1]) - tm.assert_indexing_slices_equivalent(ser, SLC[:("c", 2):-1], SLC[:9:-1]) + tm.assert_indexing_slices_equivalent(ser, SLC[("c", 2) :: -1], SLC[10::-1]) + tm.assert_indexing_slices_equivalent(ser, SLC[: ("c", 2) : -1], SLC[:9:-1]) tm.assert_indexing_slices_equivalent( - ser, SLC[("e", 0):("c", 2):-1], SLC[16:9:-1] + ser, SLC[("e", 0) : ("c", 2) : -1], SLC[16:9:-1] ) def test_multiindex_slice_first_level(self): diff --git a/pandas/tests/indexing/test_loc.py b/pandas/tests/indexing/test_loc.py index c455b0bc8599b..c897afaeeee0e 100644 --- a/pandas/tests/indexing/test_loc.py +++ b/pandas/tests/indexing/test_loc.py @@ -1818,7 +1818,7 @@ def test_loc_setitem_multiindex_slice(self): ) result = Series([1, 1, 1, 1, 1, 1, 1, 1], index=index) - result.loc[("baz", "one"):("foo", "two")] = 100 + result.loc[("baz", "one") : ("foo", "two")] = 100 expected = Series([1, 1, 100, 100, 100, 100, 1, 1], index=index) @@ -2842,7 +2842,7 @@ def test_loc_axis_1_slice(): index=tuple("ABCDEFGHIJ"), columns=MultiIndex.from_tuples(cols), ) - result = df.loc(axis=1)[(2014, 9):(2015, 8)] + result = df.loc(axis=1)[(2014, 9) : (2015, 8)] expected = DataFrame( np.ones((10, 4)), index=tuple("ABCDEFGHIJ"), diff --git a/pandas/tests/io/formats/style/test_html.py b/pandas/tests/io/formats/style/test_html.py index 1e345eb82ed3c..8cb06e3b7619d 100644 --- a/pandas/tests/io/formats/style/test_html.py +++ b/pandas/tests/io/formats/style/test_html.py @@ -93,11 +93,7 @@ def test_w3_html_format(styler): lambda x: "att1:v1;" ).set_table_attributes('class="my-cls1" style="attr3:v3;"').set_td_classes( DataFrame(["my-cls2"], index=["a"], columns=["A"]) - ).format( - "{:.1f}" - ).set_caption( - "A comprehensive test" - ) + ).format("{:.1f}").set_caption("A comprehensive test") expected = dedent( """\