Skip to content
2 changes: 1 addition & 1 deletion pandas-stubs/_testing/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def assert_frame_equal(
def assert_equal(left, right, **kwargs: Any) -> None: ...
def assert_sp_array_equal(left: SparseArray, right: SparseArray) -> None: ...
def assert_contains_all(iterable: Iterable[T], dic: Container[T]) -> None: ...
def assert_copy(iter1: Iterable[T], iter2: Iterable[T], **eql_kwargs) -> None: ...
def assert_copy(iter1: Iterable[T], iter2: Iterable[T], **eql_kwargs: Any) -> None: ...
@contextmanager
def assert_produces_warning(
expected_warning: (
Expand Down
2 changes: 2 additions & 0 deletions pandas-stubs/core/arrays/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ from pandas._typing import (
from pandas.core.dtypes.dtypes import ExtensionDtype as ExtensionDtype

class ExtensionArray:
def __array__(self, dtype=...) -> np_1darray: ...
def __array_ufunc__(self, ufunc, method, *inputs: Any, **kwargs: Any): ...
@overload
def __getitem__(self, item: ScalarIndexer) -> Any: ...
@overload
Expand Down
1 change: 0 additions & 1 deletion pandas-stubs/core/arrays/boolean.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class BooleanArray(BaseMaskedArray):
) -> None: ...
@property
def dtype(self): ...
def __array_ufunc__(self, ufunc, method, *inputs, **kwargs: Any): ...
def __setitem__(self, key, value) -> None: ...
def astype(self, dtype, copy: bool = True): ...
def any(self, *, skipna: bool = ..., **kwargs: Any): ...
Expand Down
3 changes: 0 additions & 3 deletions pandas-stubs/core/arrays/categorical.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ class Categorical(ExtensionArray):
@property
def shape(self): ...
def shift(self, periods=1, fill_value=...): ...
def __array__(self, dtype=...) -> np_1darray: ...
def __array_ufunc__(self, ufunc, method, *inputs, **kwargs: Any): ...
@property
def T(self): ...
@property
Expand All @@ -112,7 +110,6 @@ class Categorical(ExtensionArray):
def take(
self, indexer: TakeIndexer, *, allow_fill: bool = ..., fill_value=...
) -> Categorical: ...
def __len__(self) -> int: ...
def __iter__(self): ...
def __contains__(self, key) -> bool: ...
@overload
Expand Down
2 changes: 0 additions & 2 deletions pandas-stubs/core/arrays/datetimelike.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,8 @@ class DatetimeLikeArrayMixin(ExtensionOpsMixin, ExtensionArray):
def asi8(self) -> np.ndarray: ...
@property
def nbytes(self): ...
def __array__(self, dtype=...) -> np.ndarray: ...
@property
def size(self) -> int: ...
def __len__(self) -> int: ...
@overload
def __getitem__(self, key: ScalarIndexer) -> DTScalarOrNaT: ...
@overload
Expand Down
1 change: 0 additions & 1 deletion pandas-stubs/core/arrays/datetimes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class DatetimeArray(DatetimeLikeArrayMixin, TimelikeOps, DatelikeOps):
def tzinfo(self) -> _tzinfo | None: ...
@property
def is_normalized(self): ...
def __array__(self, dtype=...) -> np.ndarray: ...
def __iter__(self): ...
def astype(self, dtype, copy: bool = True): ...
def tz_convert(self, tz: TimeZones): ...
Expand Down
3 changes: 0 additions & 3 deletions pandas-stubs/core/arrays/integer.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Any

from pandas.core.arrays.masked import BaseMaskedArray

from pandas._libs.missing import NAType
Expand All @@ -19,7 +17,6 @@ class IntegerArray(BaseMaskedArray):
@property
def dtype(self) -> _IntegerDtype: ...
def __init__(self, values, mask, copy: bool = ...) -> None: ...
def __array_ufunc__(self, ufunc, method, *inputs, **kwargs: Any): ...
def __setitem__(self, key, value) -> None: ...
def astype(self, dtype, copy: bool = True): ...

Expand Down
2 changes: 0 additions & 2 deletions pandas-stubs/core/arrays/interval.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ class IntervalArray(IntervalMixin, ExtensionArray):
dtype=None,
): ...
def __iter__(self): ...
def __len__(self) -> int: ...
@overload
def __getitem__(self, key: ScalarIndexer) -> IntervalOrNA: ...
@overload
Expand Down Expand Up @@ -100,7 +99,6 @@ class IntervalArray(IntervalMixin, ExtensionArray):
def mid(self) -> Index: ...
@property
def is_non_overlapping_monotonic(self) -> bool: ...
def __array__(self, dtype=...) -> np_1darray: ...
def __arrow_array__(self, type=...): ...
def to_tuples(self, na_tuple: bool = True): ...
def repeat(self, repeats, axis: Axis | None = ...): ...
Expand Down
2 changes: 0 additions & 2 deletions pandas-stubs/core/arrays/masked.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class BaseMaskedArray(ExtensionArray, ExtensionOpsMixin):
@overload
def __getitem__(self, item: SequenceIndexer) -> Self: ...
def __iter__(self): ...
def __len__(self) -> int: ...
def __invert__(self): ...
def to_numpy(
self,
Expand All @@ -32,7 +31,6 @@ class BaseMaskedArray(ExtensionArray, ExtensionOpsMixin):
na_value: Scalar = ...,
) -> np.ndarray: ...
__array_priority__: int = ...
def __array__(self, dtype=...) -> np.ndarray: ...
def __arrow_array__(self, type=...): ...
def isna(self): ...
@property
Expand Down
5 changes: 1 addition & 4 deletions pandas-stubs/core/arrays/numpy_.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Any

import numpy as np
from numpy.lib.mixins import NDArrayOperatorsMixin
from pandas.core.arrays.base import (
Expand All @@ -15,5 +13,4 @@ class PandasDtype(ExtensionDtype):
@property
def itemsize(self) -> int: ...

class PandasArray(ExtensionArray, ExtensionOpsMixin, NDArrayOperatorsMixin):
def __array_ufunc__(self, ufunc, method, *inputs, **kwargs: Any): ...
class PandasArray(ExtensionArray, ExtensionOpsMixin, NDArrayOperatorsMixin): ...
2 changes: 0 additions & 2 deletions pandas-stubs/core/arrays/period.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import numpy as np
from pandas import PeriodDtype
from pandas.core.arrays.datetimelike import (
DatelikeOps,
Expand All @@ -13,7 +12,6 @@ class PeriodArray(DatetimeLikeArrayMixin, DatelikeOps):
def __init__(self, values, freq=..., dtype=..., copy: bool = ...) -> None: ...
@property
def dtype(self) -> PeriodDtype: ...
def __array__(self, dtype=...) -> np.ndarray: ...
def __arrow_array__(self, type=...): ...
year: int = ...
month: int = ...
Expand Down
4 changes: 0 additions & 4 deletions pandas-stubs/core/arrays/sparse/array.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ from typing import (
overload,
)

import numpy as np
from pandas.core.arrays import (
ExtensionArray,
ExtensionOpsMixin,
Expand Down Expand Up @@ -33,7 +32,6 @@ class SparseArray(ExtensionArray, ExtensionOpsMixin):
) -> None: ...
@classmethod
def from_spmatrix(cls, data): ...
def __array__(self, dtype=..., copy=...) -> np.ndarray: ...
def __setitem__(self, key, value) -> None: ...
@property
def sp_index(self): ...
Expand All @@ -47,7 +45,6 @@ class SparseArray(ExtensionArray, ExtensionOpsMixin):
def fill_value(self, value) -> None: ...
@property
def kind(self) -> str: ...
def __len__(self) -> int: ...
@property
def nbytes(self) -> int: ...
@property
Expand Down Expand Up @@ -78,5 +75,4 @@ class SparseArray(ExtensionArray, ExtensionOpsMixin):
def mean(self, axis: int = ..., *args: Any, **kwargs: Any): ...
@property
def T(self): ...
def __array_ufunc__(self, ufunc, method, *inputs, **kwargs: Any): ...
def __abs__(self): ...
3 changes: 2 additions & 1 deletion pandas-stubs/core/indexes/category.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ from typing_extensions import Self
from pandas._typing import (
S1,
DtypeArg,
np_1darray,
)

class CategoricalIndex(ExtensionIndex[S1], accessor.PandasDelegate):
Expand All @@ -35,7 +36,7 @@ class CategoricalIndex(ExtensionIndex[S1], accessor.PandasDelegate):
def __contains__(self, key) -> bool: ...
def __array__(
self, dtype: DtypeArg = ..., copy: bool | None = ...
) -> np.ndarray: ...
) -> np_1darray: ...
@property
def is_unique(self) -> bool: ...
@property
Expand Down
1 change: 0 additions & 1 deletion pandas-stubs/core/indexes/range.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ class RangeIndex(_IndexSubclassBase[int, np.int64]):
return_indexers: bool = ...,
sort: bool = ...,
): ...
def __len__(self) -> int: ...
@property
def size(self) -> int: ...
def __floordiv__(self, other): ...
Expand Down
8 changes: 5 additions & 3 deletions pandas-stubs/plotting/_misc.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def radviz(
ax: Axes | None = None,
color: _Color | Sequence[_Color] | None = None,
colormap: str | Colormap | None = None,
**kwds,
**kwds: Any,
) -> Axes: ...
def andrews_curves(
frame: DataFrame,
Expand All @@ -65,7 +65,7 @@ def bootstrap_plot(
fig: Figure | None = None,
size: int = 50,
samples: int = 500,
**kwds,
**kwds: Any,
) -> Figure: ...
def parallel_coordinates(
frame: DataFrame,
Expand All @@ -81,7 +81,9 @@ def parallel_coordinates(
sort_labels: bool = False,
**kwargs: Any,
) -> Axes: ...
def lag_plot(series: Series, lag: int = 1, ax: Axes | None = None, **kwds) -> Axes: ...
def lag_plot(
series: Series, lag: int = 1, ax: Axes | None = None, **kwds: Any
) -> Axes: ...
def autocorrelation_plot(
series: Series, ax: Axes | None = None, **kwargs: Any
) -> Axes: ...
Expand Down
8 changes: 2 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ fix = true
[tool.ruff.lint]
extend-select = ["ALL"]
ignore = [
# The following rules are ignored permanently for good reasons
"COM", # https://docs.astral.sh/ruff/rules/#flake8-commas-com
"D", # https://docs.astral.sh/ruff/rules/#pydocstyle-d
"E501", # handled by black https://docs.astral.sh/ruff/rules/line-too-long/
Expand All @@ -200,14 +199,11 @@ ignore = [
"PYI001", # https://docs.astral.sh/ruff/rules/unprefixed-type-param/
"PYI042", # https://docs.astral.sh/ruff/rules/snake-case-type-alias/
"TD003", # https://docs.astral.sh/ruff/rules/missing-todo-link/
"ERA001", "ANN", "PLR0402", "PLC0105"
"ERA001", "ANN001", "ANN201", "ANN204", "ANN206", "ANN401", "PLR0402", "PLC0105"
]
"scripts/*" = [
# The following rules are ignored permanently for good reasons
"EM", # https://docs.astral.sh/ruff/rules/#flake8-errmsg-em
"S603", # https://docs.astral.sh/ruff/rules/subprocess-without-shell-equals-true/
# The following rules are ignored temporarily. Either fix them or move to the permanent list above.
"TRY", "PT", "BLE"
]
"tests/*" = [
# The following rules are ignored permanently for good reasons
Expand All @@ -223,7 +219,7 @@ ignore = [
"A001", # https://docs.astral.sh/ruff/rules/builtin-variable-shadowing/
"PYI042", # https://docs.astral.sh/ruff/rules/snake-case-type-alias/
"SLF001", # https://docs.astral.sh/ruff/rules/private-member-access/
"ANN001", "ANN002", "ANN201", "ANN202", "ANN204", "ANN206", "ANN401", "ARG", "ERA", "RUF", "SIM", "TRY", "PT", "NPY", "N", "DTZ", "PLR", "TC", "PGH", "PTH", "S311", "C901"
"ANN001", "ANN201", "ANN204", "ANN206", "ANN401", "ARG", "ERA", "RUF", "SIM", "TRY", "PT", "NPY", "N", "DTZ", "PLR", "TC", "PGH", "PTH", "S311", "C901"
]
"tests/test_io.py" = [
# The following rules are ignored permanently for good reasons
Expand Down
4 changes: 2 additions & 2 deletions scripts/_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __rollback_job(steps: deque[Step]) -> None:
logger.warning(f"Undoing: {step.name}")
try:
step.rollback()
except Exception:
except Exception: # noqa: BLE001
logger.error(
f"Rollback of Step: '{step.name}' failed! The project could be in a unstable mode."
)
Expand All @@ -47,7 +47,7 @@ def run_job(steps: list[Step]) -> None:
rollback_steps.append(step)
step.run()

except Exception:
except Exception: # noqa: BLE001
logger.error(f"Step: '{step.name}' failed!")
__rollback_job(rollback_steps)
failed = True
Expand Down
6 changes: 3 additions & 3 deletions scripts/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@


def test(
src: bool = False,
dist: bool = False,
type_checker: Literal["", "mypy", "pyright"] = "",
src: bool = False, # noqa: PT028
dist: bool = False, # noqa: PT028
type_checker: Literal["", "mypy", "pyright"] = "", # noqa: PT028
) -> None:
steps = []
if src:
Expand Down
8 changes: 6 additions & 2 deletions scripts/test/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ def rename_src() -> None:
if Path(r"pandas-stubs").exists():
Path(r"pandas-stubs").rename("_pandas-stubs")
else:
raise FileNotFoundError("'pandas-stubs' folder does not exists.")
raise FileNotFoundError( # noqa: TRY003
"'pandas-stubs' folder does not exists."
)


def mypy_dist() -> None:
Expand All @@ -84,7 +86,9 @@ def restore_src() -> None:
if Path(r"_pandas-stubs").exists():
Path(r"_pandas-stubs").rename("pandas-stubs")
else:
raise FileNotFoundError("'_pandas-stubs' folder does not exists.")
raise FileNotFoundError( # noqa: TRY003
"'_pandas-stubs' folder does not exists."
)


def nightly_pandas() -> None:
Expand Down
26 changes: 17 additions & 9 deletions tests/extension/decimal/array.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from __future__ import annotations

from builtins import type as type_t
from collections.abc import Callable
import decimal
import numbers
import sys
from typing import Any
from typing import (
Any,
cast,
)

import numpy as np
from pandas.api.extensions import (
Expand Down Expand Up @@ -125,7 +129,9 @@ def to_numpy(
result = np.asarray([round(x, decimals) for x in result])
return result

def __array_ufunc__(self, ufunc: np.ufunc, method: str, *inputs, **kwargs: Any):
def __array_ufunc__(
self, ufunc: np.ufunc, method: str, *inputs: Any, **kwargs: Any
):
#
if not all(
isinstance(t, self._HANDLED_TYPES + (DecimalArray,)) for t in inputs
Expand All @@ -147,7 +153,7 @@ def __array_ufunc__(self, ufunc: np.ufunc, method: str, *inputs, **kwargs: Any):
if result is not NotImplemented:
return result

def reconstruct(x):
def reconstruct(x) -> decimal.Decimal | numbers.Number | DecimalArray:
if isinstance(x, (decimal.Decimal, numbers.Number)):
return x
return DecimalArray._from_sequence(x)
Expand Down Expand Up @@ -220,10 +226,10 @@ def isna(self):
return np.array([x.is_nan() for x in self._data], dtype=bool)

@property
def _na_value(self):
def _na_value(self) -> decimal.Decimal:
return decimal.Decimal("NaN")

def _formatter(self, boxed=False):
def _formatter(self, boxed=False) -> Callable[..., str]:
if boxed:
return "Decimal: {}".format
return repr
Expand All @@ -232,7 +238,7 @@ def _formatter(self, boxed=False):
def _concat_same_type(cls, to_concat):
return cls(np.concatenate([x._data for x in to_concat]))

def _reduce(self, name: str, *, skipna: bool = True, **kwargs: Any):
def _reduce(self, name: str, *, skipna: bool = True, **kwargs: Any) -> Any:
if skipna:
# If we don't have any NAs, we can ignore skipna
if self.isna().any():
Expand All @@ -251,9 +257,9 @@ def _reduce(self, name: str, *, skipna: bool = True, **kwargs: Any):
) from err
return op(axis=0)

def _cmp_method(self, other, op):
def _cmp_method(self, other, op) -> np.ndarray[tuple[int], np.dtype[np.bool_]]:
# For use with OpsMixin
def convert_values(param):
def convert_values(param) -> ExtensionArray | list[Any]:
if isinstance(param, ExtensionArray) or is_list_like(param):
ovalues = param
else:
Expand All @@ -268,7 +274,9 @@ def convert_values(param):
# a TypeError should be raised
res = [op(a, b) for (a, b) in zip(lvalues, rvalues)]

return np.asarray(res, dtype=bool)
return cast(
np.ndarray[tuple[int], np.dtype[np.bool_]], np.asarray(res, dtype=bool)
)

def value_counts(self, dropna: bool = True):
from pandas.core.algorithms import value_counts
Expand Down
Loading