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

Fix nightly and support 2.1.1 #781

Merged
merged 4 commits into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 6 additions & 1 deletion pandas-stubs/_libs/tslibs/offsets.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,12 @@ class BusinessMixin(SingleConstructorOffset):
self, n: int = ..., normalize: bool = ..., offset: timedelta = ...
) -> None: ...

class BusinessDay(BusinessMixin): ...
# Changed from implementation because it is not allowed for `PeriodDtype`
class BusinessDay(BaseOffset):
def __init__(
self, n: int = ..., normalize: bool = ..., offset: timedelta = ...
) -> None: ...
def __reduce__(self): ...

class BusinessHour(BusinessMixin):
def __init__(
Expand Down
8 changes: 7 additions & 1 deletion pandas-stubs/core/dtypes/dtypes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ from pandas.core.series import Series

from pandas._libs import NaTType
from pandas._libs.tslibs import BaseOffset
from pandas._libs.tslibs.offsets import (
RelativeDeltaOffset,
SingleConstructorOffset,
)
from pandas._typing import (
Ordered,
npt,
Expand Down Expand Up @@ -48,7 +52,9 @@ class DatetimeTZDtype(PandasExtensionDtype):
def na_value(self) -> NaTType: ...

class PeriodDtype(PandasExtensionDtype):
def __init__(self, freq: str | BaseOffset = ...) -> None: ...
def __init__(
self, freq: str | SingleConstructorOffset | RelativeDeltaOffset = ...
) -> None: ...
@property
def freq(self) -> BaseOffset: ...
@property
Expand Down
22 changes: 11 additions & 11 deletions pandas-stubs/core/frame.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ class DataFrame(NDFrame, OpsMixin):
def groupby(
self,
by: Scalar,
axis: Axis = ...,
axis: AxisIndex = ...,
level: Level | None = ...,
as_index: _bool = ...,
sort: _bool = ...,
Expand All @@ -1011,7 +1011,7 @@ class DataFrame(NDFrame, OpsMixin):
def groupby(
self,
by: DatetimeIndex,
axis: Axis = ...,
axis: AxisIndex = ...,
level: Level | None = ...,
as_index: _bool = ...,
sort: _bool = ...,
Expand All @@ -1024,7 +1024,7 @@ class DataFrame(NDFrame, OpsMixin):
def groupby(
self,
by: TimedeltaIndex,
axis: Axis = ...,
axis: AxisIndex = ...,
level: Level | None = ...,
as_index: _bool = ...,
sort: _bool = ...,
Expand All @@ -1037,7 +1037,7 @@ class DataFrame(NDFrame, OpsMixin):
def groupby(
self,
by: PeriodIndex,
axis: Axis = ...,
axis: AxisIndex = ...,
level: Level | None = ...,
as_index: _bool = ...,
sort: _bool = ...,
Expand All @@ -1050,7 +1050,7 @@ class DataFrame(NDFrame, OpsMixin):
def groupby(
self,
by: IntervalIndex[IntervalT],
axis: Axis = ...,
axis: AxisIndex = ...,
level: Level | None = ...,
as_index: _bool = ...,
sort: _bool = ...,
Expand All @@ -1063,7 +1063,7 @@ class DataFrame(NDFrame, OpsMixin):
def groupby(
self,
by: MultiIndex | GroupByObjectNonScalar | None = ...,
axis: Axis = ...,
axis: AxisIndex = ...,
level: Level | None = ...,
as_index: _bool = ...,
sort: _bool = ...,
Expand All @@ -1076,7 +1076,7 @@ class DataFrame(NDFrame, OpsMixin):
def groupby(
self,
by: Series[SeriesByT],
axis: Axis = ...,
axis: AxisIndex = ...,
level: Level | None = ...,
as_index: _bool = ...,
sort: _bool = ...,
Expand All @@ -1089,7 +1089,7 @@ class DataFrame(NDFrame, OpsMixin):
def groupby(
self,
by: CategoricalIndex | Index | Series,
axis: Axis = ...,
axis: AxisIndex = ...,
level: Level | None = ...,
as_index: _bool = ...,
sort: _bool = ...,
Expand Down Expand Up @@ -1643,7 +1643,7 @@ class DataFrame(NDFrame, OpsMixin):
def expanding(
self,
min_periods: int = ...,
axis: Axis = ...,
axis: AxisIndex = ...,
method: CalculationMethod = ...,
) -> Expanding[DataFrame]: ...
@overload
Expand Down Expand Up @@ -1962,7 +1962,7 @@ class DataFrame(NDFrame, OpsMixin):
min_periods: int | None = ...,
center: _bool = ...,
on: Hashable | None = ...,
axis: Axis = ...,
axis: AxisIndex = ...,
closed: IntervalClosedType | None = ...,
step: int | None = ...,
method: CalculationMethod = ...,
Expand All @@ -1976,7 +1976,7 @@ class DataFrame(NDFrame, OpsMixin):
min_periods: int | None = ...,
center: _bool = ...,
on: Hashable | None = ...,
axis: Axis = ...,
axis: AxisIndex = ...,
closed: IntervalClosedType | None = ...,
step: int | None = ...,
method: CalculationMethod = ...,
Expand Down
15 changes: 12 additions & 3 deletions pandas-stubs/core/groupby/generic.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,24 @@ class DataFrameGroupBy(GroupBy, Generic[ByT]):
# error: Overload 3 for "apply" will never be used because its parameters overlap overload 1
@overload
def apply( # type: ignore[misc]
self, func: Callable[[DataFrame], Scalar | list | dict], *args, **kwargs
self,
func: Callable[[DataFrame], Scalar | list | dict],
*args,
**kwargs,
) -> Series: ...
@overload
def apply(
self, func: Callable[[DataFrame], Series | DataFrame], *args, **kwargs
self,
func: Callable[[DataFrame], Series | DataFrame],
*args,
**kwargs,
) -> DataFrame: ...
@overload
def apply( # pyright: ignore[reportOverlappingOverload]
self, func: Callable[[Iterable], float], *args, **kwargs
self,
func: Callable[[Iterable], float],
*args,
**kwargs,
) -> DataFrame: ...
# error: overload 1 overlaps overload 2 because of different return types
@overload
Expand Down
4 changes: 0 additions & 4 deletions pandas-stubs/core/series.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1637,12 +1637,10 @@ class Series(IndexOpsMixin[S1], NDFrame):
min_periods: int = ...,
adjust: _bool = ...,
ignore_na: _bool = ...,
axis: AxisIndex = ...,
) -> ExponentialMovingWindow[Series]: ...
def expanding(
self,
min_periods: int = ...,
axis: AxisIndex = ...,
method: CalculationMethod = ...,
) -> Expanding[Series]: ...
def floordiv(
Expand Down Expand Up @@ -1825,7 +1823,6 @@ class Series(IndexOpsMixin[S1], NDFrame):
min_periods: int | None = ...,
center: _bool = ...,
on: _str | None = ...,
axis: AxisIndex = ...,
closed: IntervalClosedType | None = ...,
step: int | None = ...,
method: CalculationMethod = ...,
Expand All @@ -1839,7 +1836,6 @@ class Series(IndexOpsMixin[S1], NDFrame):
min_periods: int | None = ...,
center: _bool = ...,
on: _str | None = ...,
axis: AxisIndex = ...,
closed: IntervalClosedType | None = ...,
step: int | None = ...,
method: CalculationMethod = ...,
Expand Down
13 changes: 9 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ packages = [
[tool.poetry.dependencies]
python = ">=3.9"
types-pytz = ">= 2022.1.1"
numpy = ">=1.25.0"
numpy = { version = ">=1.26.0", python = "<3.13" }

[tool.poetry.dev-dependencies]
mypy = "1.5.1"
pandas = "2.0.3"
pandas = "2.1.1"
pyarrow = ">=10.0.1"
pytest = ">=7.1.2"
pyright = ">= 1.1.327"
# pyright 1.1.327 has bug fixed in 1.1.328
pyright = "1.1.326"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which bug is affecting pandas-stubs?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not clear, but 1.1.328 is installed in VS Code pre-release and within VS Code, I get no complaints, but when I install 1.1.327, it doesn't like the use of this pattern in core/generic.pyi:

def somefunc(self: NDFrameT, someargs) -> NDFrameT: ...

complaining like this:

core\generic.pyi:60:15 - error: Type of parameter "self" must be a supertype of its class "NDFrame" (reportGeneralTypeIssues)

1.1.328 is in VSCode, but not on pypi yet

Copy link
Member

@twoertwein twoertwein Sep 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would Self fix the issue?

edit: could also be done later

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If 1.1.328 also fails once released, then I will try that

poethepoet = ">=0.16.5"
loguru = ">=0.6.0"
typing-extensions = ">=4.4.0"
Expand All @@ -58,7 +59,7 @@ odfpy = ">=1.4.1"
xarray = ">=22.6.0"
tabulate = ">=0.8.10"
jinja2 = ">=3.1"
scipy = ">=1.9.1"
scipy = { version = ">=1.9.1", python = "<3.13" }
SQLAlchemy = ">=2.0.12"
types-python-dateutil = ">=2.8.19"
numexpr = "<2.8.5" # https://github.com/pandas-dev/pandas/issues/54449
Expand Down Expand Up @@ -195,3 +196,7 @@ useLibraryCodeForTypes = false

[tool.codespell]
ignore-words-list = "indext, mose, sav, ser"

# Next line needed to avoid poetry complaint
[tool.setuptools_scm]

2 changes: 1 addition & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

TYPE_CHECKING_INVALID_USAGE: Final = TYPE_CHECKING
WINDOWS = os.name == "nt" or "cygwin" in platform.system().lower()
PD_LTE_20 = Version(pd.__version__) < Version("2.0.999")
PD_LTE_21 = Version(pd.__version__) < Version("2.1.999")


def check(actual: T, klass: type, dtype: type | None = None, attr: str = "left") -> T:
Expand Down
10 changes: 6 additions & 4 deletions tests/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ def test_period_dtype() -> None:
p_dt = pd.PeriodDtype(freq="D")
check(assert_type(p_dt, pd.PeriodDtype), pd.PeriodDtype)
check(assert_type(pd.PeriodDtype(freq=Day()), pd.PeriodDtype), pd.PeriodDtype)
check(
assert_type(pd.PeriodDtype(freq=BusinessDay()), pd.PeriodDtype), pd.PeriodDtype
)
if TYPE_CHECKING_INVALID_USAGE:
pd.PeriodDtype(freq=CustomBusinessDay()) # TODO(raises on 2.1)
pd.PeriodDtype(
freq=CustomBusinessDay() # type:ignore[arg-type] # pyright: ignore[reportGeneralTypeIssues]
)
pd.PeriodDtype(
freq=BusinessDay() # type:ignore[arg-type] # pyright: ignore[reportGeneralTypeIssues]
)
check(
assert_type(p_dt.freq, pd.tseries.offsets.BaseOffset),
pd.tseries.offsets.DateOffset,
Expand Down
Loading