Skip to content

numpy 1.25.0, pyright 1.1.316, mypy 1.4.1 #741

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 2 commits into from
Jul 5, 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
8 changes: 7 additions & 1 deletion pandas-stubs/_libs/tslibs/timestamps.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ from datetime import (
timedelta,
tzinfo as _tzinfo,
)
import sys
from time import struct_time
from typing import (
ClassVar,
Expand Down Expand Up @@ -45,6 +46,11 @@ _Nonexistent: TypeAlias = (
Literal["raise", "NaT", "shift_backward", "shift_forward"] | Timedelta | timedelta
)

if sys.version_info >= (3, 9):
from datetime import _IsoCalendarDate
else:
_IsoCalendarDate: TypeAlias = tuple[int, int, int]

class Timestamp(datetime):
min: ClassVar[Timestamp]
max: ClassVar[Timestamp]
Expand Down Expand Up @@ -227,7 +233,7 @@ class Timestamp(datetime):
def __ne__(self, other: object) -> Literal[True]: ...
def weekday(self) -> int: ...
def isoweekday(self) -> int: ...
def isocalendar(self) -> tuple[int, int, int]: ...
def isocalendar(self) -> _IsoCalendarDate: ...
@property
def is_leap_year(self) -> bool: ...
@property
Expand Down
15 changes: 8 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,17 @@ packages = [
[tool.poetry.dependencies]
python = ">=3.8"
types-pytz = ">= 2022.1.1"
numpy = "<=1.24.3"
numpy = [
{version = "<=1.24.3", python = "<=3.8"},
{version = ">=1.25.0", python = ">=3.9"}
]

[tool.poetry.dev-dependencies]
mypy = "1.3.0"
pandas = "2.0.2"
mypy = "1.4.1"
pandas = "2.0.3"
pyarrow = ">=10.0.1"
pytest = ">=7.1.2"
pyright = "<= 1.1.313"
pyright = ">= 1.1.316"
poethepoet = ">=0.16.5"
loguru = ">=0.6.0"
typing-extensions = ">=4.4.0"
Expand All @@ -49,7 +52,7 @@ pre-commit = ">=2.19.0"
black = ">=23.3.0"
isort = ">=5.12.0"
openpyxl = ">=3.0.10"
tables = { version = ">=3.7.0" , python = "<4"} # 3.8.0 depends on blosc2 which caps python to <4
tables = { version = ">=3.8.0" , python = "<4"} # 3.8.0 depends on blosc2 which caps python to <4
lxml = ">=4.9.1"
pyreadstat = ">=1.2.0"
xlrd = ">=2.0.1"
Expand Down Expand Up @@ -135,8 +138,6 @@ follow_imports = "normal"
follow_imports_for_stubs = false
no_site_packages = false
no_silence_site_packages = false
# Platform configuration
python_version = "3.8"
# Disallow dynamic typing
disallow_any_unimported = false # TODO
disallow_any_expr = false # TODO
Expand Down
107 changes: 64 additions & 43 deletions tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
TYPE_CHECKING_INVALID_USAGE,
WINDOWS,
check,
pytest_warns_bounded,
)

from pandas.io.api import to_pickle
Expand Down Expand Up @@ -371,57 +372,77 @@ def test_hdfstore():
assert_type(store.select("df", start=0, stop=1), Union[DataFrame, Series]),
DataFrame,
)
check(
assert_type(store.select("df", where="index>=1"), Union[DataFrame, Series]),
DataFrame,
)
check(
assert_type(
store.select("df", where=Term("index>=1")),
Union[DataFrame, Series],
),
DataFrame,
)
check(
assert_type(
store.select("df", where=[Term("index>=1")]),
Union[DataFrame, Series],
),
DataFrame,
)
check(assert_type(store.get("df"), Union[DataFrame, Series]), DataFrame)
for key in store:
check(assert_type(key, str), str)
check(assert_type(store.close(), None), type(None))
with pytest_warns_bounded(
DeprecationWarning,
match="`alltrue` is deprecated as of NumPy 1.25.0",
lower="1.24.99",
version_str=np.__version__,
):
check(
assert_type(
store.select("df", where="index>=1"), Union[DataFrame, Series]
),
DataFrame,
)
check(
assert_type(
store.select("df", where=Term("index>=1")),
Union[DataFrame, Series],
),
DataFrame,
)
check(
assert_type(
store.select("df", where=[Term("index>=1")]),
Union[DataFrame, Series],
),
DataFrame,
)
check(assert_type(store.get("df"), Union[DataFrame, Series]), DataFrame)
for key in store:
check(assert_type(key, str), str)
check(assert_type(store.close(), None), type(None))

store = HDFStore(path, model="r")
check(
assert_type(read_hdf(store, "df"), Union[DataFrame, Series]),
DataFrame,
)
store.close()
store = HDFStore(path, model="r")
check(
assert_type(read_hdf(store, "df"), Union[DataFrame, Series]),
DataFrame,
)
store.close()


def test_read_hdf_iterator():
with ensure_clean() as path:
check(assert_type(DF.to_hdf(path, "df", format="table"), None), type(None))
ti = read_hdf(path, chunksize=1)
check(assert_type(ti, TableIterator), TableIterator)
ti.close()
with pytest_warns_bounded(
DeprecationWarning,
match="`alltrue` is deprecated as of NumPy 1.25.0",
lower="1.24.99",
version_str=np.__version__,
):
with ensure_clean() as path:
check(assert_type(DF.to_hdf(path, "df", format="table"), None), type(None))
ti = read_hdf(path, chunksize=1)
check(assert_type(ti, TableIterator), TableIterator)
ti.close()

ti = read_hdf(path, "df", iterator=True)
check(assert_type(ti, TableIterator), TableIterator)
for _ in ti:
pass
ti.close()
ti = read_hdf(path, "df", iterator=True)
check(assert_type(ti, TableIterator), TableIterator)
for _ in ti:
pass
ti.close()


def test_hdf_context_manager():
with ensure_clean() as path:
check(assert_type(DF.to_hdf(path, "df", format="table"), None), type(None))
with HDFStore(path, mode="r") as store:
check(assert_type(store.is_open, bool), bool)
check(assert_type(store.get("df"), Union[DataFrame, Series]), DataFrame)
with pytest_warns_bounded(
DeprecationWarning,
match="`alltrue` is deprecated as of NumPy 1.25.0",
lower="1.24.99",
version_str=np.__version__,
):
with ensure_clean() as path:
check(assert_type(DF.to_hdf(path, "df", format="table"), None), type(None))
with HDFStore(path, mode="r") as store:
check(assert_type(store.is_open, bool), bool)
check(assert_type(store.get("df"), Union[DataFrame, Series]), DataFrame)


def test_hdf_series():
Expand Down