Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make IndexOpsMixin (and Index) generic #760

Merged
merged 25 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
4929ecb
interpolate method
twoertwein Aug 2, 2023
2775a58
WIP
twoertwein Aug 2, 2023
9e40ddf
mypy handles Never differently - at least asssert that the method nev…
twoertwein Aug 3, 2023
68abe4d
use Self
twoertwein Aug 3, 2023
2cfbdb0
a few more S1/Self
twoertwein Aug 3, 2023
ebcc389
fix tests
twoertwein Aug 3, 2023
24d42fa
more tests
twoertwein Aug 3, 2023
f3802d3
add an ignore to let mypy pass
twoertwein Aug 3, 2023
92eab41
compat with old python versions
twoertwein Aug 3, 2023
6e04d8e
fix CategoricalIndex; MultiIndex should probably be Index[tuple[S1, .…
twoertwein Aug 3, 2023
e7a2d3b
Revert "interpolate method"
twoertwein Aug 3, 2023
d12a72a
many more overloads for subclasses (I wish pandas would not handle su…
twoertwein Aug 4, 2023
87c62d0
remove PandasObject - it caused the pyright issues but it provides no…
twoertwein Aug 4, 2023
9ce5fc4
works (except for np.ndarray)
twoertwein Aug 4, 2023
05b9c15
Merge remote-tracking branch 'upstream/main' into iter_interpolate
twoertwein Aug 8, 2023
d32f534
address the easy-to-fix comments
twoertwein Aug 8, 2023
4f13109
overloads for numpy
twoertwein Aug 9, 2023
bd39625
did numexpr break the CI?
twoertwein Aug 9, 2023
8c48567
lie: df.columns -> Index[str]
twoertwein Aug 9, 2023
67f5e8d
new ruff has far more pyi rules
twoertwein Aug 9, 2023
566c918
Make it clear that both mypy&pyright infer Never; but only pyright de…
twoertwein Aug 10, 2023
ff5ee58
use type aliases instead of npt
twoertwein Aug 10, 2023
c8d2019
fix issue with floordiv for mypy
Dr-Irv Aug 13, 2023
585c93b
fix comment in arraylike
Dr-Irv Aug 13, 2023
7ac1ea5
Merge pull request #3 from Dr-Irv/pr760
twoertwein Aug 14, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repos:
hooks:
- id: isort
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.282
rev: v0.0.278
hooks:
- id: ruff
args: [
Expand Down
3 changes: 2 additions & 1 deletion pandas-stubs/_libs/tslibs/timedeltas.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,9 @@ class Timedelta(timedelta):
def __rmul__(self, other: Series[int]) -> TimedeltaSeries: ...
@overload
def __rmul__(self, other: Series[float]) -> TimedeltaSeries: ...
# maybe related to https://github.com/python/mypy/issues/10755
@overload
def __rmul__(self, other: Index[int] | Index[float]) -> TimedeltaIndex: ...
def __rmul__(self, other: Index[int] | Index[float]) -> TimedeltaIndex: ... # type: ignore[misc]
# Override due to more types supported than dt.timedelta
# error: Signature of "__floordiv__" incompatible with supertype "timedelta"
@overload # type: ignore[override]
Expand Down
20 changes: 0 additions & 20 deletions pandas-stubs/_typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -664,26 +664,6 @@ StataDateFormat: TypeAlias = Literal[
]

FillnaOptions: TypeAlias = Literal["backfill", "bfill", "ffill", "pad"]
InterpolateOptions: TypeAlias = Literal[
"linear",
"time",
"index",
"pad",
"nearest",
"zero",
"slinear",
"quadratic",
"cubic",
"barycentric",
"polynomial",
"krogh",
"piecewise_polynomial",
"spline",
"pchip",
"akima",
"cubicspline",
"from_derivatives",
]
ReplaceMethod: TypeAlias = Literal["pad", "ffill", "bfill"]
SortKind: TypeAlias = Literal["quicksort", "mergesort", "heapsort", "stable"]
NaPosition: TypeAlias = Literal["first", "last"]
Expand Down
3 changes: 0 additions & 3 deletions pandas-stubs/core/accessor.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
from typing import Any

class DirNamesMixin:
def __dir__(self): ...
Dr-Irv marked this conversation as resolved.
Show resolved Hide resolved

class PandasDelegate: ...

def delegate_names(
Expand Down
9 changes: 3 additions & 6 deletions pandas-stubs/core/arrays/categorical.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ import numpy as np
from pandas import Series
from pandas.core.accessor import PandasDelegate as PandasDelegate
from pandas.core.arrays.base import ExtensionArray as ExtensionArray
from pandas.core.base import (
NoNewAttributesMixin as NoNewAttributesMixin,
PandasObject as PandasObject,
)
from pandas.core.base import NoNewAttributesMixin as NoNewAttributesMixin
from pandas.core.indexes.base import Index

from pandas._typing import (
Expand All @@ -33,7 +30,7 @@ from pandas.core.dtypes.dtypes import CategoricalDtype as CategoricalDtype

def contains(cat, key, container): ...

class Categorical(ExtensionArray, PandasObject):
class Categorical(ExtensionArray):
__array_priority__: int = ...
def __init__(
self,
Expand Down Expand Up @@ -185,7 +182,7 @@ class Categorical(ExtensionArray, PandasObject):
def repeat(self, repeats, axis=...): ...
def isin(self, values): ...

class CategoricalAccessor(PandasDelegate, PandasObject, NoNewAttributesMixin):
class CategoricalAccessor(PandasDelegate, NoNewAttributesMixin):
def __init__(self, data) -> None: ...
@property
def codes(self) -> Series[int]: ...
Expand Down
3 changes: 1 addition & 2 deletions pandas-stubs/core/arrays/sparse/array.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ from pandas.core.arrays import (
ExtensionArray,
ExtensionOpsMixin,
)
from pandas.core.base import PandasObject

from pandas._typing import TakeIndexer

class SparseArray(PandasObject, ExtensionArray, ExtensionOpsMixin):
class SparseArray(ExtensionArray, ExtensionOpsMixin):
def __init__(
self,
data,
Expand Down
4 changes: 0 additions & 4 deletions pandas-stubs/core/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ from typing import (

import numpy as np
from pandas import Index
from pandas.core.accessor import DirNamesMixin
from pandas.core.arraylike import OpsMixin
from pandas.core.arrays import ExtensionArray
from pandas.core.arrays.categorical import Categorical
Expand All @@ -21,9 +20,6 @@ from pandas._typing import (
npt,
)

class PandasObject(DirNamesMixin):
def __sizeof__(self) -> int: ...

class NoNewAttributesMixin:
def __setattr__(self, key, value) -> None: ...

Expand Down
1 change: 0 additions & 1 deletion pandas-stubs/core/computation/ops.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class Term:
def ndim(self) -> int: ...

class Constant(Term):
def __init__(self, value, env, side=..., encoding=...) -> None: ...
twoertwein marked this conversation as resolved.
Show resolved Hide resolved
@property
def name(self): ...

Expand Down
2 changes: 1 addition & 1 deletion pandas-stubs/core/computation/pytables.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Term(ops.Term):
def value(self, new_value) -> None: ...

class Constant(Term):
def __init__(self, value, env: PyTablesScope, side=..., encoding=...) -> None: ...
def __init__(self, name, env: PyTablesScope, side=..., encoding=...) -> None: ...

class BinOp(ops.BinOp):
op: str
Expand Down
7 changes: 3 additions & 4 deletions pandas-stubs/core/frame.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ from pandas._typing import (
IndexingInt,
IndexLabel,
IndexType,
InterpolateOptions,
IntervalClosedType,
IntervalT,
JoinHow,
Expand Down Expand Up @@ -1705,7 +1704,7 @@ class DataFrame(NDFrame, OpsMixin):
@overload
def interpolate(
self,
method: InterpolateOptions = ...,
method: _str = ...,
*,
axis: Axis = ...,
limit: int | None = ...,
Expand All @@ -1718,7 +1717,7 @@ class DataFrame(NDFrame, OpsMixin):
@overload
def interpolate(
self,
method: InterpolateOptions = ...,
method: _str = ...,
*,
axis: Axis = ...,
limit: int | None = ...,
Expand All @@ -1731,7 +1730,7 @@ class DataFrame(NDFrame, OpsMixin):
@overload
def interpolate(
self,
method: InterpolateOptions = ...,
method: _str = ...,
*,
axis: Axis = ...,
limit: int | None = ...,
Expand Down
3 changes: 1 addition & 2 deletions pandas-stubs/core/generic.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ from typing import (

import numpy as np
from pandas import Index
from pandas.core.base import PandasObject
import pandas.core.indexing as indexing
from pandas.core.series import Series
import sqlalchemy.engine
Expand Down Expand Up @@ -54,7 +53,7 @@ from pandas.io.sql import SQLTable
_bool = bool
_str = str

class NDFrame(PandasObject, indexing.IndexingMixin):
class NDFrame(indexing.IndexingMixin):
__hash__: ClassVar[None] # type: ignore[assignment]

def set_flags(
Expand Down
9 changes: 3 additions & 6 deletions pandas-stubs/core/groupby/groupby.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ from collections.abc import (
)

import numpy as np
from pandas.core.base import (
PandasObject,
SelectionMixin,
)
from pandas.core.base import SelectionMixin
from pandas.core.frame import DataFrame
from pandas.core.generic import NDFrame
from pandas.core.groupby import ops
Expand All @@ -21,12 +18,12 @@ from pandas._typing import (
npt,
)

class GroupByPlot(PandasObject):
class GroupByPlot:
def __init__(self, groupby) -> None: ...
def __call__(self, *args, **kwargs): ...
def __getattr__(self, name: str): ...

class BaseGroupBy(PandasObject, SelectionMixin[NDFrameT]):
class BaseGroupBy(SelectionMixin[NDFrameT]):
level = ...
as_index = ...
keys = ...
Expand Down
12 changes: 3 additions & 9 deletions pandas-stubs/core/indexes/accessors.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ from pandas.core.arrays import (
DatetimeArray,
PeriodArray,
)
from pandas.core.base import (
NoNewAttributesMixin,
PandasObject,
)
from pandas.core.base import NoNewAttributesMixin
from pandas.core.frame import DataFrame
from pandas.core.series import (
PeriodSeries,
Expand All @@ -39,7 +36,7 @@ from pandas._typing import (
np_ndarray_bool,
)

class Properties(PandasDelegate, PandasObject, NoNewAttributesMixin):
class Properties(PandasDelegate, NoNewAttributesMixin):
def __init__(self, data: Series, orig) -> None: ...

_DTFieldOpsReturnType = TypeVar("_DTFieldOpsReturnType", Series[int], Index[int])
Expand Down Expand Up @@ -346,7 +343,6 @@ class PeriodProperties(
_IsLeapYearProperty,
_FreqProperty[BaseOffset],
): ...

class CombinedDatetimelikeProperties(
DatetimeProperties[
Series[int],
Expand All @@ -361,9 +357,7 @@ class CombinedDatetimelikeProperties(
],
_TimedeltaPropertiesNoRounding[Series[int], Series[float]],
_PeriodProperties,
):
def __new__(cls, data: Series): ...

): ...
class TimestampProperties(
DatetimeProperties[
Series[int],
Expand Down
Loading