Skip to content

Commit 29afb64

Browse files
committed
simpler solution
1 parent b598270 commit 29afb64

File tree

5 files changed

+371
-456
lines changed

5 files changed

+371
-456
lines changed

pyproject.toml

+8
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,14 @@ useLibraryCodeForTypes = false
197197
[tool.codespell]
198198
ignore-words-list = "indext, mose, sav, ser"
199199

200+
[tool.pytest.ini_options]
201+
filterwarnings = [
202+
# treat warnings as errors
203+
"error",
204+
# until there is a new dateutil release: github.com/dateutil/dateutil/pull/1285
205+
"ignore:datetime.datetime.utc:DeprecationWarning",
206+
]
207+
200208
# Next line needed to avoid poetry complaint
201209
[tool.setuptools_scm]
202210

scripts/test/run.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ def pyright_src():
1515
subprocess.run(cmd, check=True)
1616

1717

18-
def pytest(flags: tuple[str, ...] = ("-Werror",)):
19-
cmd = ["pytest", "--cache-clear", *flags]
18+
def pytest():
19+
cmd = ["pytest", "--cache-clear"]
2020
subprocess.run(cmd, check=True)
2121

2222

tests/__init__.py

+4-10
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,23 @@
77
)
88
import os
99
import platform
10-
import sys
1110
from typing import (
1211
TYPE_CHECKING,
1312
Final,
14-
TypeVar,
1513
)
1614

15+
import pandas as pd
16+
from pandas.util.version import Version
1717
import pytest
1818

19-
if sys.version_info < (3, 12):
20-
import pandas as pd
21-
else:
22-
with pytest.warns(DeprecationWarning, match="datetime.datetime.utcfromtimestamp"):
23-
import pandas as pd
24-
from pandas.util.version import Version
19+
from pandas._typing import T
2520

26-
_T = TypeVar("_T")
2721
TYPE_CHECKING_INVALID_USAGE: Final = TYPE_CHECKING
2822
WINDOWS = os.name == "nt" or "cygwin" in platform.system().lower()
2923
PD_LTE_21 = Version(pd.__version__) < Version("2.1.999")
3024

3125

32-
def check(actual: _T, klass: type, dtype: type | None = None, attr: str = "left") -> _T:
26+
def check(actual: T, klass: type, dtype: type | None = None, attr: str = "left") -> T:
3327
if not isinstance(actual, klass):
3428
raise RuntimeError(f"Expected type '{klass}' but got '{type(actual)}'")
3529
if dtype is None:

tests/test_frame.py

+18-25
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import io
1515
import itertools
1616
from pathlib import Path
17-
import platform
1817
import string
1918
from typing import (
2019
TYPE_CHECKING,
@@ -1822,30 +1821,24 @@ def test_frame_getitem_isin() -> None:
18221821
def test_to_excel() -> None:
18231822
df = pd.DataFrame(data={"col1": [1, 2], "col2": [3, 4]})
18241823

1825-
with pytest_warns_bounded(
1826-
DeprecationWarning,
1827-
match="datetime.datetime.utcnow",
1828-
lower="3.11.99",
1829-
version_str=platform.python_version(),
1830-
):
1831-
with ensure_clean() as path:
1832-
df.to_excel(path, engine="openpyxl")
1833-
check(assert_type(pd.read_excel(path), pd.DataFrame), pd.DataFrame)
1834-
with ensure_clean() as path:
1835-
df.to_excel(Path(path), engine="openpyxl")
1836-
check(assert_type(pd.read_excel(path), pd.DataFrame), pd.DataFrame)
1837-
with ensure_clean() as path:
1838-
df.to_excel(path, engine="openpyxl", startrow=1, startcol=1, header=False)
1839-
check(assert_type(pd.read_excel(path), pd.DataFrame), pd.DataFrame)
1840-
with ensure_clean() as path:
1841-
df.to_excel(path, engine="openpyxl", sheet_name="sheet", index=False)
1842-
check(assert_type(pd.read_excel(path), pd.DataFrame), pd.DataFrame)
1843-
with ensure_clean() as path:
1844-
df.to_excel(path, engine="openpyxl", header=["x", "y"])
1845-
check(assert_type(pd.read_excel(path), pd.DataFrame), pd.DataFrame)
1846-
with ensure_clean() as path:
1847-
df.to_excel(path, engine="openpyxl", columns=["col1"])
1848-
check(assert_type(pd.read_excel(path), pd.DataFrame), pd.DataFrame)
1824+
with ensure_clean() as path:
1825+
df.to_excel(path, engine="openpyxl")
1826+
check(assert_type(pd.read_excel(path), pd.DataFrame), pd.DataFrame)
1827+
with ensure_clean() as path:
1828+
df.to_excel(Path(path), engine="openpyxl")
1829+
check(assert_type(pd.read_excel(path), pd.DataFrame), pd.DataFrame)
1830+
with ensure_clean() as path:
1831+
df.to_excel(path, engine="openpyxl", startrow=1, startcol=1, header=False)
1832+
check(assert_type(pd.read_excel(path), pd.DataFrame), pd.DataFrame)
1833+
with ensure_clean() as path:
1834+
df.to_excel(path, engine="openpyxl", sheet_name="sheet", index=False)
1835+
check(assert_type(pd.read_excel(path), pd.DataFrame), pd.DataFrame)
1836+
with ensure_clean() as path:
1837+
df.to_excel(path, engine="openpyxl", header=["x", "y"])
1838+
check(assert_type(pd.read_excel(path), pd.DataFrame), pd.DataFrame)
1839+
with ensure_clean() as path:
1840+
df.to_excel(path, engine="openpyxl", columns=["col1"])
1841+
check(assert_type(pd.read_excel(path), pd.DataFrame), pd.DataFrame)
18491842

18501843

18511844
def test_join() -> None:

0 commit comments

Comments
 (0)