Skip to content

Commit b072842

Browse files
authored
run pytest against nightly (#238)
* optional pytest run against nightly * full version for pre-commit * wo shell * Revert "wo shell" This reverts commit fc51e9b.
1 parent e446958 commit b072842

File tree

7 files changed

+119
-62
lines changed

7 files changed

+119
-62
lines changed

.github/setup/action.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Install project dependencies
2+
3+
inputs:
4+
python-version:
5+
required: true
6+
os:
7+
required: true
8+
9+
runs:
10+
using: composite
11+
steps:
12+
13+
- name: Set up Python
14+
uses: actions/setup-python@v4
15+
with:
16+
python-version: ${{ inputs.python-version }}
17+
18+
- name: Install Poetry
19+
shell: bash
20+
run: python -m pip install poetry
21+
22+
- name: Determine poetry version
23+
shell: bash
24+
run: echo "::set-output name=VERSION::$(poetry --version)"
25+
id: poetry_version
26+
27+
- name: Cache poetry.lock
28+
uses: actions/cache@v3
29+
with:
30+
path: poetry.lock
31+
key: ${{ inputs.os }}-${{ inputs.python-version }}-poetry-${{ steps.poetry_version.outputs.VERSION }}-${{ hashFiles('pyproject.toml') }}
32+
33+
- name: Install project dependencies
34+
shell: bash
35+
run: poetry install -vvv --no-root

.github/workflows/test.yml

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: 'Test'
33
on:
44
[push, pull_request, workflow_dispatch]
55
jobs:
6-
test:
6+
released:
77
runs-on: ${{ matrix.os }}
88
timeout-minutes: 10
99
strategy:
@@ -13,34 +13,17 @@ jobs:
1313
python-version: ['3.8', '3.9', '3.10']
1414

1515
steps:
16-
1716
- uses: actions/checkout@v3
1817

19-
- name: Set up Python ${{ matrix.python-version }}
20-
uses: actions/setup-python@v4
18+
- name: Install project dependencies
19+
uses: ./.github/setup
2120
with:
21+
os: ${{ matrix.os }}
2222
python-version: ${{ matrix.python-version }}
2323

24-
- name: Install Poetry
25-
run: pip install poetry
26-
27-
- name: Determine poetry version
28-
run: echo "::set-output name=VERSION::$(poetry --version)"
29-
id: poetry_version
30-
31-
- name: Cache poetry.lock
32-
uses: actions/cache@v3
33-
with:
34-
path: poetry.lock
35-
key: ${{ matrix.os }}-${{ matrix.python-version }}-poetry-${{ steps.poetry_version.outputs.VERSION }}-${{ hashFiles('pyproject.toml') }}
36-
37-
- name: Install project dependencies
38-
run: poetry install -vvv --no-root
39-
4024
- name: Show poetry python location (Windows)
4125
shell: pwsh
42-
run: |
43-
poetry run where python
26+
run: poetry run where python
4427
if: matrix.os == 'windows-latest'
4528

4629
- name: Run mypy on 'tests' (using the local stubs) and on the local stubs
@@ -52,8 +35,30 @@ jobs:
5235
- name: Run pytest
5336
run: poetry run poe pytest
5437

55-
- if: matrix.python-version == '3.8' && matrix.os == 'ubuntu-latest'
56-
uses: pre-commit/action@v3.0.0
57-
5838
- name: Install pandas-stubs and run tests on the installed stubs
5939
run: poetry run poe test_dist
40+
41+
nightly:
42+
runs-on: ubuntu-latest
43+
timeout-minutes: 10
44+
45+
steps:
46+
- uses: actions/checkout@v3
47+
48+
- name: Install project dependencies
49+
uses: ./.github/setup
50+
with:
51+
os: ubuntu-latest
52+
python-version: '3.10'
53+
54+
- name: Run pytest (against pandas nightly)
55+
run: poetry run poe pytest --nightly
56+
57+
precommit:
58+
runs-on: ubuntu-latest
59+
timeout-minutes: 10
60+
61+
steps:
62+
- uses: actions/checkout@v3
63+
64+
- uses: pre-commit/action@v3.0.0

pyproject.toml

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

7474
[tool.poe.tasks.pytest]
7575
help = "Run pytest"
76-
script = "scripts.test.run:pytest"
76+
script = "scripts.test:pytest(nightly)"
77+
args = [{name = "nightly", positional = false, default = false, type = "boolean", required = false, help= "Use pandas nightly (off by default)"}]
7778

7879
[tool.poe.tasks.style]
7980
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
@@ -117,13 +117,10 @@ def test_types_to_csv() -> None:
117117

118118
def test_types_to_csv_when_path_passed() -> None:
119119
df = pd.DataFrame(data={"col1": [1, 2], "col2": [3, 4]})
120-
path: Path = Path("./dummy_path.txt")
121-
try:
122-
assert not path.exists()
120+
with ensure_clean() as file:
121+
path = Path(file)
123122
df.to_csv(path)
124123
df5: pd.DataFrame = pd.read_csv(path)
125-
finally:
126-
path.unlink()
127124

128125

129126
def test_types_copy() -> None:
@@ -801,16 +798,17 @@ def test_to_markdown() -> None:
801798
def test_types_to_feather() -> None:
802799
pytest.importorskip("pyarrow")
803800
df = pd.DataFrame(data={"col1": [1, 1, 2], "col2": [3, 4, 5]})
804-
df.to_feather("dummy_path")
805-
# kwargs for pyarrow.feather.write_feather added in 1.1.0 https://pandas.pydata.org/docs/whatsnew/v1.1.0.html
806-
df.to_feather("dummy_path", compression="zstd", compression_level=3, chunksize=2)
807-
808-
# to_feather has been able to accept a buffer since pandas 1.0.0
809-
# See https://pandas.pydata.org/docs/whatsnew/v1.0.0.html
810-
# Docstring and type were updated in 1.2.0.
811-
# https://github.com/pandas-dev/pandas/pull/35408
812801
with ensure_clean() as path:
813802
df.to_feather(path)
803+
# kwargs for pyarrow.feather.write_feather added in 1.1.0 https://pandas.pydata.org/docs/whatsnew/v1.1.0.html
804+
df.to_feather(path, compression="zstd", compression_level=3, chunksize=2)
805+
806+
# to_feather has been able to accept a buffer since pandas 1.0.0
807+
# See https://pandas.pydata.org/docs/whatsnew/v1.0.0.html
808+
# Docstring and type were updated in 1.2.0.
809+
# https://github.com/pandas-dev/pandas/pull/35408
810+
with open(path, mode="wb") as file:
811+
df.to_feather(file)
814812

815813

816814
# 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
@@ -169,43 +169,51 @@ def test_clipboard_iterator():
169169
def test_sas_bdat() -> None:
170170
path = pathlib.Path(CWD, "data", "airline.sas7bdat")
171171
check(assert_type(read_sas(path), DataFrame), DataFrame)
172-
check(
172+
with check(
173173
assert_type(read_sas(path, iterator=True), Union[SAS7BDATReader, XportReader]),
174174
SAS7BDATReader,
175-
)
176-
check(
175+
):
176+
pass
177+
with check(
177178
assert_type(read_sas(path, iterator=True, format="sas7bdat"), SAS7BDATReader),
178179
SAS7BDATReader,
179-
)
180-
check(
180+
):
181+
pass
182+
with check(
181183
assert_type(read_sas(path, chunksize=1), Union[SAS7BDATReader, XportReader]),
182184
SAS7BDATReader,
183-
)
184-
check(
185+
):
186+
pass
187+
with check(
185188
assert_type(read_sas(path, chunksize=1, format="sas7bdat"), SAS7BDATReader),
186189
SAS7BDATReader,
187-
)
190+
):
191+
pass
188192

189193

190194
def test_sas_xport() -> None:
191195
path = pathlib.Path(CWD, "data", "SSHSV1_A.xpt")
192196
check(assert_type(read_sas(path), DataFrame), DataFrame)
193-
check(
197+
with check(
194198
assert_type(read_sas(path, iterator=True), Union[SAS7BDATReader, XportReader]),
195199
XportReader,
196-
)
197-
check(
200+
):
201+
pass
202+
with check(
198203
assert_type(read_sas(path, iterator=True, format="xport"), XportReader),
199204
XportReader,
200-
)
201-
check(
205+
):
206+
pass
207+
with check(
202208
assert_type(read_sas(path, chunksize=1), Union[SAS7BDATReader, XportReader]),
203209
XportReader,
204-
)
205-
check(
210+
):
211+
pass
212+
with check(
206213
assert_type(read_sas(path, chunksize=1, format="xport"), XportReader),
207214
XportReader,
208-
)
215+
):
216+
pass
209217

210218

211219
def test_hdf():

0 commit comments

Comments
 (0)