Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

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 @@ -138,7 +138,7 @@ repos:
types: [python]
stages: [manual]
additional_dependencies: &pyright_dependencies
- pyright@1.1.305
- pyright@1.1.318
- id: pyright
# note: assumes python env is setup and activated
name: pyright reportGeneralTypeIssues
Expand Down
16 changes: 9 additions & 7 deletions pandas/_libs/tslibs/offsets.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from datetime import (
datetime,
time,
timedelta,
)
from typing import (
Expand All @@ -14,6 +15,7 @@ import numpy as np

from pandas._libs.tslibs.nattype import NaTType
from pandas._typing import (
OffsetCalendar,
Self,
npt,
)
Expand Down Expand Up @@ -141,8 +143,8 @@ class BusinessHour(BusinessMixin):
self,
n: int = ...,
normalize: bool = ...,
start: str | Collection[str] = ...,
end: str | Collection[str] = ...,
start: str | time | Collection[str | time] = ...,
end: str | time | Collection[str | time] = ...,
offset: timedelta = ...,
) -> None: ...

Expand Down Expand Up @@ -228,7 +230,7 @@ class _CustomBusinessMonth(BusinessMixin):
normalize: bool = ...,
weekmask: str = ...,
holidays: list | None = ...,
calendar: np.busdaycalendar | None = ...,
calendar: OffsetCalendar | None = ...,
offset: timedelta = ...,
) -> None: ...

Expand All @@ -239,7 +241,7 @@ class CustomBusinessDay(BusinessDay):
normalize: bool = ...,
weekmask: str = ...,
holidays: list | None = ...,
calendar: np.busdaycalendar | None = ...,
calendar: OffsetCalendar | None = ...,
offset: timedelta = ...,
) -> None: ...

Expand All @@ -250,9 +252,9 @@ class CustomBusinessHour(BusinessHour):
normalize: bool = ...,
weekmask: str = ...,
holidays: list | None = ...,
calendar: np.busdaycalendar | None = ...,
start: str = ...,
end: str = ...,
calendar: OffsetCalendar | None = ...,
start: str | time | Collection[str | time] = ...,
end: str | time | Collection[str | time] = ...,
offset: timedelta = ...,
) -> None: ...

Expand Down
22 changes: 17 additions & 5 deletions pandas/_libs/tslibs/timestamps.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ from pandas._libs.tslibs import (
Tick,
Timedelta,
)
from pandas._typing import Self
from pandas._typing import (
Self,
TimestampNonexistent,
)

_DatetimeT = TypeVar("_DatetimeT", bound=datetime)

Expand Down Expand Up @@ -187,18 +190,27 @@ class Timestamp(datetime):
self,
tz: _tzinfo | str | None,
ambiguous: str = ...,
nonexistent: str = ...,
nonexistent: TimestampNonexistent = ...,
) -> Self: ...
def normalize(self) -> Self: ...
# TODO: round/floor/ceil could return NaT?
def round(
self, freq: str, ambiguous: bool | str = ..., nonexistent: str = ...
self,
freq: str,
ambiguous: bool | str = ...,
nonexistent: TimestampNonexistent = ...,
) -> Self: ...
def floor(
self, freq: str, ambiguous: bool | str = ..., nonexistent: str = ...
self,
freq: str,
ambiguous: bool | str = ...,
nonexistent: TimestampNonexistent = ...,
) -> Self: ...
def ceil(
self, freq: str, ambiguous: bool | str = ..., nonexistent: str = ...
self,
freq: str,
ambiguous: bool | str = ...,
nonexistent: TimestampNonexistent = ...,
) -> Self: ...
def day_name(self, locale: str | None = ...) -> str: ...
def month_name(self, locale: str | None = ...) -> str: ...
Expand Down
14 changes: 11 additions & 3 deletions pandas/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Sequence,
)
from datetime import (
date,
datetime,
timedelta,
tzinfo,
Expand Down Expand Up @@ -68,6 +69,7 @@
from pandas.core.window.rolling import BaseWindow

from pandas.io.formats.format import EngFormatter
from pandas.tseries.holiday import AbstractHolidayCalendar

ScalarLike_co = Union[
int,
Expand All @@ -89,7 +91,7 @@
from typing_extensions import TypeGuard # pyright: ignore[reportUnusedImport]

if sys.version_info >= (3, 11):
from typing import Self
from typing import Self # pyright: ignore[reportUnusedImport]
else:
from typing_extensions import Self # pyright: ignore[reportUnusedImport]
else:
Expand Down Expand Up @@ -117,14 +119,17 @@
PythonScalar = Union[str, float, bool]
DatetimeLikeScalar = Union["Period", "Timestamp", "Timedelta"]
PandasScalar = Union["Period", "Timestamp", "Timedelta", "Interval"]
Scalar = Union[PythonScalar, PandasScalar, np.datetime64, np.timedelta64, datetime]
Scalar = Union[PythonScalar, PandasScalar, np.datetime64, np.timedelta64, date]
IntStrT = TypeVar("IntStrT", int, str)


# timestamp and timedelta convertible types

TimestampConvertibleTypes = Union[
"Timestamp", datetime, np.datetime64, np.int64, float, str
"Timestamp", date, np.datetime64, np.int64, float, str
]
TimestampNonexistent = Union[
Literal["shift_forward", "shift_backward", "NaT", "raise"], timedelta
]
TimedeltaConvertibleTypes = Union[
"Timedelta", timedelta, np.timedelta64, np.int64, float, str
Expand Down Expand Up @@ -466,3 +471,6 @@ def closed(self) -> bool:

# ExcelWriter
ExcelWriterIfSheetExists = Literal["error", "new", "replace", "overlay"]

# Offsets
OffsetCalendar = Union[np.busdaycalendar, "AbstractHolidayCalendar"]
2 changes: 1 addition & 1 deletion pandas/core/arrays/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ def raise_on_incompatible(left, right):

def period_array(
data: Sequence[Period | str | None] | AnyArrayLike,
freq: str | Tick | None = None,
freq: str | Tick | BaseOffset | None = None,
copy: bool = False,
) -> PeriodArray:
"""
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,7 @@ def bdate_range(
start=None,
end=None,
periods: int | None = None,
freq: Frequency = "B",
freq: Frequency | dt.timedelta = "B",
tz=None,
normalize: bool = True,
name: Hashable | None = None,
Expand Down
20 changes: 9 additions & 11 deletions pandas/core/reshape/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,24 +497,22 @@ def _clean_keys_and_objs(
if isinstance(objs, abc.Mapping):
if keys is None:
keys = list(objs.keys())
objs = [objs[k] for k in keys]
objs_list = [objs[k] for k in keys]
else:
objs = list(objs)
objs_list = list(objs)

if len(objs) == 0:
if len(objs_list) == 0:
raise ValueError("No objects to concatenate")

if keys is None:
objs = list(com.not_none(*objs))
objs_list = list(com.not_none(*objs_list))
else:
# GH#1649
clean_keys = []
clean_objs = []
if is_iterator(keys):
keys = list(keys)
if is_iterator(objs):
objs = list(objs)
Copy link
Member Author

Choose a reason for hiding this comment

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

This if should not be needed as objs was always a list at that point - let's see whether the tests agree.

if len(keys) != len(objs):
if len(keys) != len(objs_list):
# GH#43485
warnings.warn(
"The behavior of pd.concat with len(keys) != len(objs) is "
Expand All @@ -523,12 +521,12 @@ def _clean_keys_and_objs(
FutureWarning,
stacklevel=find_stack_level(),
)
for k, v in zip(keys, objs):
for k, v in zip(keys, objs_list):
if v is None:
continue
clean_keys.append(k)
clean_objs.append(v)
objs = clean_objs
objs_list = clean_objs

if isinstance(keys, MultiIndex):
# TODO: retain levels?
Expand All @@ -537,10 +535,10 @@ def _clean_keys_and_objs(
name = getattr(keys, "name", None)
keys = Index(clean_keys, name=name, dtype=getattr(keys, "dtype", None))

if len(objs) == 0:
if len(objs_list) == 0:
raise ValueError("All objects passed were None")

return objs, keys
return objs_list, keys

def _get_sample_object(
self,
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/tools/datetimes.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from collections import abc
from datetime import datetime
from datetime import date
from functools import partial
from itertools import islice
from typing import (
Expand Down Expand Up @@ -98,7 +98,7 @@

ArrayConvertible = Union[list, tuple, AnyArrayLike]
Scalar = Union[float, str]
DatetimeScalar = Union[Scalar, datetime]
DatetimeScalar = Union[Scalar, date, np.datetime64]

DatetimeScalarOrArrayConvertible = Union[DatetimeScalar, ArrayConvertible]

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/tools/times.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

def to_time(
arg,
format=None,
format: str | None = None,
infer_time_format: bool = False,
errors: DateTimeErrorChoices = "raise",
):
Expand Down
10 changes: 6 additions & 4 deletions pandas/io/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1023,10 +1023,12 @@ def __init__(
self.archive_name = archive_name

kwargs.setdefault("compression", zipfile.ZIP_DEFLATED)
# error: Argument 1 to "ZipFile" has incompatible type "Union[
# Union[str, PathLike[str]], ReadBuffer[bytes], WriteBuffer[bytes]]";
# expected "Union[Union[str, PathLike[str]], IO[bytes]]"
self.buffer = zipfile.ZipFile(file, mode, **kwargs) # type: ignore[arg-type]
# error: No overload variant of "ZipFile" matches argument types "str |
# PathLike[str] | ReadBuffer[bytes] | WriteBuffer[bytes]", "str", "dict[str,
# Any]"
self.buffer = zipfile.ZipFile( # type: ignore[call-overload]
file, mode, **kwargs
)

def infer_filename(self) -> str | None:
"""
Expand Down
Loading