Skip to content

Commit 4fda762

Browse files
committed
optional pytest run against nightly
1 parent 426e31d commit 4fda762

File tree

6 files changed

+59
-37
lines changed

6 files changed

+59
-37
lines changed

.github/workflows/test.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,8 @@ jobs:
5757

5858
- name: Install pandas-stubs and run tests on the installed stubs
5959
run: poetry run poe test_dist
60+
61+
# pandas nightly might have deprecated older python versions
62+
- if: matrix.python-version == '3.10' && matrix.os == 'ubuntu-latest'
63+
name: Run pytest (against pandas nightly)
64+
run: poetry run poe pytest --nightly

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ script = "scripts.test:test(dist=True)"
7070

7171
[tool.poe.tasks.pytest]
7272
help = "Run pytest"
73-
script = "scripts.test.run:pytest"
73+
script = "scripts.test:pytest(nightly)"
74+
args = [{name = "nightly", positional = false, default = false, type = "boolean", required = false, help= "Use pandas nightly (off by default)"}]
7475

7576
[tool.poe.tasks.style]
7677
help = "Run pre-commit"

scripts/test/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,8 @@ def stubtest(allowlist: str, check_missing: bool, nightly: bool) -> None:
4646
if nightly:
4747
steps.append(_step.nightly)
4848
run_job(steps + [stubtest])
49+
50+
51+
def pytest(nightly: bool) -> None:
52+
steps = [_step.nightly] if nightly else []
53+
run_job(steps + [_step.pytest])

scripts/test/run.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def pyright_src():
1414

1515

1616
def pytest():
17-
cmd = ["pytest", "--cache-clear"]
17+
cmd = ["pytest", "--cache-clear", "-Werror"]
1818
subprocess.run(cmd, check=True)
1919

2020

@@ -81,22 +81,27 @@ def restore_src():
8181

8282

8383
def nightly_pandas():
84-
cmd = [sys.executable, "-m", "pip", "uninstall", "-y", "pandas"]
85-
subprocess.run(cmd, check=True)
8684
cmd = [
8785
sys.executable,
8886
"-m",
8987
"pip",
9088
"install",
91-
"-i",
89+
"--use-deprecated=legacy-resolver",
90+
"--upgrade",
91+
"--index-url",
9292
"https://pypi.anaconda.org/scipy-wheels-nightly/simple",
9393
"pandas",
9494
]
9595
subprocess.run(cmd, check=True)
9696

9797

9898
def released_pandas():
99-
cmd = [sys.executable, "-m", "pip", "uninstall", "-y", "pandas"]
100-
subprocess.run(cmd, check=True)
101-
cmd = [sys.executable, "-m", "pip", "install", "pandas"]
99+
# query pandas version
100+
text = Path("pyproject.toml").read_text()
101+
version_line = next(
102+
line for line in text.splitlines() if line.startswith("pandas = ")
103+
)
104+
version = version_line.split('"')[1]
105+
106+
cmd = [sys.executable, "-m", "pip", "install", f"pandas=={version}"]
102107
subprocess.run(cmd, check=True)

tests/test_frame.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,10 @@ def test_types_to_csv() -> None:
110110

111111
def test_types_to_csv_when_path_passed() -> None:
112112
df = pd.DataFrame(data={"col1": [1, 2], "col2": [3, 4]})
113-
path: Path = Path("./dummy_path.txt")
114-
try:
115-
assert not path.exists()
113+
with ensure_clean() as file:
114+
path = Path(file)
116115
df.to_csv(path)
117116
df5: pd.DataFrame = pd.read_csv(path)
118-
finally:
119-
path.unlink()
120117

121118

122119
def test_types_copy() -> None:
@@ -788,16 +785,17 @@ def test_to_markdown() -> None:
788785
def test_types_to_feather() -> None:
789786
pytest.importorskip("pyarrow")
790787
df = pd.DataFrame(data={"col1": [1, 1, 2], "col2": [3, 4, 5]})
791-
df.to_feather("dummy_path")
792-
# kwargs for pyarrow.feather.write_feather added in 1.1.0 https://pandas.pydata.org/docs/whatsnew/v1.1.0.html
793-
df.to_feather("dummy_path", compression="zstd", compression_level=3, chunksize=2)
794-
795-
# to_feather has been able to accept a buffer since pandas 1.0.0
796-
# See https://pandas.pydata.org/docs/whatsnew/v1.0.0.html
797-
# Docstring and type were updated in 1.2.0.
798-
# https://github.com/pandas-dev/pandas/pull/35408
799788
with ensure_clean() as path:
800789
df.to_feather(path)
790+
# kwargs for pyarrow.feather.write_feather added in 1.1.0 https://pandas.pydata.org/docs/whatsnew/v1.1.0.html
791+
df.to_feather(path, compression="zstd", compression_level=3, chunksize=2)
792+
793+
# to_feather has been able to accept a buffer since pandas 1.0.0
794+
# See https://pandas.pydata.org/docs/whatsnew/v1.0.0.html
795+
# Docstring and type were updated in 1.2.0.
796+
# https://github.com/pandas-dev/pandas/pull/35408
797+
with open(path, mode="wb") as file:
798+
df.to_feather(file)
801799

802800

803801
# compare() method added in 1.1.0 https://pandas.pydata.org/docs/whatsnew/v1.1.0.html

tests/test_io.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -163,43 +163,51 @@ def test_clipboard_iterator():
163163
def test_sas_bdat() -> None:
164164
path = pathlib.Path(CWD, "data", "airline.sas7bdat")
165165
check(assert_type(read_sas(path), DataFrame), DataFrame)
166-
check(
166+
with check(
167167
assert_type(read_sas(path, iterator=True), Union[SAS7BDATReader, XportReader]),
168168
SAS7BDATReader,
169-
)
170-
check(
169+
):
170+
pass
171+
with check(
171172
assert_type(read_sas(path, iterator=True, format="sas7bdat"), SAS7BDATReader),
172173
SAS7BDATReader,
173-
)
174-
check(
174+
):
175+
pass
176+
with check(
175177
assert_type(read_sas(path, chunksize=1), Union[SAS7BDATReader, XportReader]),
176178
SAS7BDATReader,
177-
)
178-
check(
179+
):
180+
pass
181+
with check(
179182
assert_type(read_sas(path, chunksize=1, format="sas7bdat"), SAS7BDATReader),
180183
SAS7BDATReader,
181-
)
184+
):
185+
pass
182186

183187

184188
def test_sas_xport() -> None:
185189
path = pathlib.Path(CWD, "data", "SSHSV1_A.xpt")
186190
check(assert_type(read_sas(path), DataFrame), DataFrame)
187-
check(
191+
with check(
188192
assert_type(read_sas(path, iterator=True), Union[SAS7BDATReader, XportReader]),
189193
XportReader,
190-
)
191-
check(
194+
):
195+
pass
196+
with check(
192197
assert_type(read_sas(path, iterator=True, format="xport"), XportReader),
193198
XportReader,
194-
)
195-
check(
199+
):
200+
pass
201+
with check(
196202
assert_type(read_sas(path, chunksize=1), Union[SAS7BDATReader, XportReader]),
197203
XportReader,
198-
)
199-
check(
204+
):
205+
pass
206+
with check(
200207
assert_type(read_sas(path, chunksize=1, format="xport"), XportReader),
201208
XportReader,
202-
)
209+
):
210+
pass
203211

204212

205213
def test_hdf():

0 commit comments

Comments
 (0)