Skip to content

TYP: misc annotations #57606

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

Merged
merged 6 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ repos:
types: [python]
stages: [manual]
additional_dependencies: &pyright_dependencies
- [email protected].350
- [email protected].351
- id: pyright
# note: assumes python env is setup and activated
name: pyright reportGeneralTypeIssues
Expand Down
33 changes: 27 additions & 6 deletions pandas/_libs/tslibs/nattype.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,24 @@ from datetime import (
timedelta,
tzinfo as _tzinfo,
)
import typing
from typing import (
Literal,
TypeAlias,
)

import numpy as np

from pandas._libs.tslibs.period import Period
from pandas._typing import Self
from pandas._typing import (
Self,
TimestampNonexistent,
)

NaT: NaTType
iNaT: int
nat_strings: set[str]

_NaTComparisonTypes: typing.TypeAlias = (
_NaTComparisonTypes: TypeAlias = (
datetime | timedelta | Period | np.datetime64 | np.timedelta64
)

Expand Down Expand Up @@ -70,9 +76,24 @@ class NaTType:
def now(self, *args, **kwargs) -> NaTType: ...
def to_pydatetime(self) -> NaTType: ...
def date(self) -> NaTType: ...
def round(self) -> NaTType: ...
def floor(self) -> NaTType: ...
def ceil(self) -> NaTType: ...
def round(
self,
freq: str,
ambiguous: bool | Literal["raise"] | NaTType = ...,
nonexistent: TimestampNonexistent = ...,
) -> NaTType: ...
def floor(
self,
freq: str,
ambiguous: bool | Literal["raise"] | NaTType = ...,
nonexistent: TimestampNonexistent = ...,
) -> NaTType: ...
def ceil(
self,
freq: str,
ambiguous: bool | Literal["raise"] | NaTType = ...,
nonexistent: TimestampNonexistent = ...,
) -> NaTType: ...
@property
def tzinfo(self) -> None: ...
@property
Expand Down
4 changes: 2 additions & 2 deletions pandas/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def __reversed__(self) -> Iterator[_T_co]:
IndexLabel = Union[Hashable, Sequence[Hashable]]
Level = Hashable
Shape = tuple[int, ...]
Suffixes = tuple[Optional[str], Optional[str]]
Suffixes = Sequence[Optional[str]]
Ordered = Optional[bool]
JSONSerializable = Optional[Union[PythonScalar, list, dict]]
Frequency = Union[str, "BaseOffset"]
Expand All @@ -226,7 +226,7 @@ def __reversed__(self) -> Iterator[_T_co]:
Dtype = Union["ExtensionDtype", NpDtype]
AstypeArg = Union["ExtensionDtype", "npt.DTypeLike"]
# DtypeArg specifies all allowable dtypes in a functions its dtype argument
DtypeArg = Union[Dtype, dict[Hashable, Dtype]]
DtypeArg = Union[Dtype, Mapping[Hashable, Dtype]]
DtypeObj = Union[np.dtype, "ExtensionDtype"]

# converters
Expand Down
6 changes: 3 additions & 3 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -4799,7 +4799,7 @@ def insert(
self,
loc: int,
column: Hashable,
value: Scalar | AnyArrayLike,
value: object,
allow_duplicates: bool | lib.NoDefault = lib.no_default,
) -> None:
"""
Expand Down Expand Up @@ -6266,7 +6266,7 @@ def dropna(
axis: Axis = 0,
how: AnyAll | lib.NoDefault = lib.no_default,
thresh: int | lib.NoDefault = lib.no_default,
subset: IndexLabel | None = None,
subset: IndexLabel | AnyArrayLike | None = None,
inplace: bool = False,
ignore_index: bool = False,
) -> DataFrame | None:
Expand Down Expand Up @@ -6390,7 +6390,7 @@ def dropna(
if subset is not None:
# subset needs to be list
if not is_list_like(subset):
subset = [subset]
subset = [cast(Hashable, subset)]
ax = self._get_axis(agg_axis)
indices = ax.get_indexer_for(subset)
check = indices == -1
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1326,7 +1326,7 @@ def hist(
xrot: float | None = None,
ylabelsize: int | None = None,
yrot: float | None = None,
figsize: tuple[int, int] | None = None,
figsize: tuple[float, float] | None = None,
bins: int | Sequence[int] = 10,
backend: str | None = None,
legend: bool = False,
Expand Down Expand Up @@ -2599,7 +2599,7 @@ def hist(
ax=None,
sharex: bool = False,
sharey: bool = False,
figsize: tuple[int, int] | None = None,
figsize: tuple[float, float] | None = None,
layout: tuple[int, int] | None = None,
bins: int | Sequence[int] = 10,
backend: str | None = None,
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/reshape/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ def merge_asof(
left_by=None,
right_by=None,
suffixes: Suffixes = ("_x", "_y"),
tolerance: int | Timedelta | None = None,
tolerance: int | datetime.timedelta | None = None,
allow_exact_matches: bool = True,
direction: str = "backward",
) -> DataFrame:
Expand Down Expand Up @@ -494,7 +494,7 @@ def merge_asof(
suffixes : 2-length sequence (tuple, list, ...)
Suffix to apply to overlapping column names in the left and right
side, respectively.
tolerance : int or Timedelta, optional, default None
tolerance : int or timedelta, optional, default None
Select asof tolerance within this range; must be compatible
with the merge index.
allow_exact_matches : bool, default True
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2891,7 +2891,7 @@ def autocorr(self, lag: int = 1) -> float:
"""
return self.corr(cast(Series, self.shift(lag)))

def dot(self, other: AnyArrayLike) -> Series | np.ndarray:
def dot(self, other: AnyArrayLike | DataFrame) -> Series | np.ndarray:
"""
Compute the dot product between the Series and the columns of other.

Expand Down
7 changes: 4 additions & 3 deletions pandas/io/excel/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
DtypeBackend,
ExcelWriterIfSheetExists,
FilePath,
HashableT,
IntStrT,
ReadBuffer,
Self,
Expand Down Expand Up @@ -382,7 +383,7 @@ def read_excel(
| str
| Sequence[int]
| Sequence[str]
| Callable[[str], bool]
| Callable[[HashableT], bool]
| None = ...,
dtype: DtypeArg | None = ...,
engine: Literal["xlrd", "openpyxl", "odf", "pyxlsb", "calamine"] | None = ...,
Expand Down Expand Up @@ -421,7 +422,7 @@ def read_excel(
| str
| Sequence[int]
| Sequence[str]
| Callable[[str], bool]
| Callable[[HashableT], bool]
| None = ...,
dtype: DtypeArg | None = ...,
engine: Literal["xlrd", "openpyxl", "odf", "pyxlsb", "calamine"] | None = ...,
Expand Down Expand Up @@ -460,7 +461,7 @@ def read_excel(
| str
| Sequence[int]
| Sequence[str]
| Callable[[str], bool]
| Callable[[HashableT], bool]
| None = None,
dtype: DtypeArg | None = None,
engine: Literal["xlrd", "openpyxl", "odf", "pyxlsb", "calamine"] | None = None,
Expand Down
Loading