diff --git a/.github/setup/action.yaml b/.github/setup/action.yaml new file mode 100644 index 000000000..fe6b568c1 --- /dev/null +++ b/.github/setup/action.yaml @@ -0,0 +1,35 @@ +name: Install project dependencies + +inputs: + python-version: + required: true + os: + required: true + +runs: + using: composite + steps: + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: ${{ inputs.python-version }} + + - name: Install Poetry + shell: bash + run: python -m pip install poetry + + - name: Determine poetry version + shell: bash + run: echo "::set-output name=VERSION::$(poetry --version)" + id: poetry_version + + - name: Cache poetry.lock + uses: actions/cache@v3 + with: + path: poetry.lock + key: ${{ inputs.os }}-${{ inputs.python-version }}-poetry-${{ steps.poetry_version.outputs.VERSION }}-${{ hashFiles('pyproject.toml') }} + + - name: Install project dependencies + shell: bash + run: poetry install -vvv --no-root diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1f195563e..9f4175ad2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,7 +3,7 @@ name: 'Test' on: [push, pull_request, workflow_dispatch] jobs: - test: + released: runs-on: ${{ matrix.os }} timeout-minutes: 10 strategy: @@ -13,34 +13,17 @@ jobs: python-version: ['3.8', '3.9', '3.10'] steps: - - uses: actions/checkout@v3 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + - name: Install project dependencies + uses: ./.github/setup with: + os: ${{ matrix.os }} python-version: ${{ matrix.python-version }} - - name: Install Poetry - run: pip install poetry - - - name: Determine poetry version - run: echo "::set-output name=VERSION::$(poetry --version)" - id: poetry_version - - - name: Cache poetry.lock - uses: actions/cache@v3 - with: - path: poetry.lock - key: ${{ matrix.os }}-${{ matrix.python-version }}-poetry-${{ steps.poetry_version.outputs.VERSION }}-${{ hashFiles('pyproject.toml') }} - - - name: Install project dependencies - run: poetry install -vvv --no-root - - name: Show poetry python location (Windows) shell: pwsh - run: | - poetry run where python + run: poetry run where python if: matrix.os == 'windows-latest' - name: Run mypy on 'tests' (using the local stubs) and on the local stubs @@ -52,8 +35,30 @@ jobs: - name: Run pytest run: poetry run poe pytest - - if: matrix.python-version == '3.8' && matrix.os == 'ubuntu-latest' - uses: pre-commit/action@v3.0.0 - - name: Install pandas-stubs and run tests on the installed stubs run: poetry run poe test_dist + + nightly: + runs-on: ubuntu-latest + timeout-minutes: 10 + + steps: + - uses: actions/checkout@v3 + + - name: Install project dependencies + uses: ./.github/setup + with: + os: ubuntu-latest + python-version: '3.10' + + - name: Run pytest (against pandas nightly) + run: poetry run poe pytest --nightly + + precommit: + runs-on: ubuntu-latest + timeout-minutes: 10 + + steps: + - uses: actions/checkout@v3 + + - uses: pre-commit/action@v3.0.0 diff --git a/pyproject.toml b/pyproject.toml index 415cc4f09..5a0b6f491 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -70,7 +70,8 @@ script = "scripts.test:test(dist=True)" [tool.poe.tasks.pytest] help = "Run pytest" -script = "scripts.test.run:pytest" +script = "scripts.test:pytest(nightly)" +args = [{name = "nightly", positional = false, default = false, type = "boolean", required = false, help= "Use pandas nightly (off by default)"}] [tool.poe.tasks.style] help = "Run pre-commit" diff --git a/scripts/test/__init__.py b/scripts/test/__init__.py index 185d7380d..02d053947 100644 --- a/scripts/test/__init__.py +++ b/scripts/test/__init__.py @@ -46,3 +46,8 @@ def stubtest(allowlist: str, check_missing: bool, nightly: bool) -> None: if nightly: steps.append(_step.nightly) run_job(steps + [stubtest]) + + +def pytest(nightly: bool) -> None: + steps = [_step.nightly] if nightly else [] + run_job(steps + [_step.pytest]) diff --git a/scripts/test/run.py b/scripts/test/run.py index 75af694e1..145e4b2b2 100644 --- a/scripts/test/run.py +++ b/scripts/test/run.py @@ -14,7 +14,7 @@ def pyright_src(): def pytest(): - cmd = ["pytest", "--cache-clear"] + cmd = ["pytest", "--cache-clear", "-Werror"] subprocess.run(cmd, check=True) @@ -81,14 +81,14 @@ def restore_src(): def nightly_pandas(): - cmd = [sys.executable, "-m", "pip", "uninstall", "-y", "pandas"] - subprocess.run(cmd, check=True) cmd = [ sys.executable, "-m", "pip", "install", - "-i", + "--use-deprecated=legacy-resolver", + "--upgrade", + "--index-url", "https://pypi.anaconda.org/scipy-wheels-nightly/simple", "pandas", ] @@ -96,7 +96,12 @@ def nightly_pandas(): def released_pandas(): - cmd = [sys.executable, "-m", "pip", "uninstall", "-y", "pandas"] - subprocess.run(cmd, check=True) - cmd = [sys.executable, "-m", "pip", "install", "pandas"] + # query pandas version + text = Path("pyproject.toml").read_text() + version_line = next( + line for line in text.splitlines() if line.startswith("pandas = ") + ) + version = version_line.split('"')[1] + + cmd = [sys.executable, "-m", "pip", "install", f"pandas=={version}"] subprocess.run(cmd, check=True) diff --git a/tests/test_frame.py b/tests/test_frame.py index e1822ebe0..58092d809 100644 --- a/tests/test_frame.py +++ b/tests/test_frame.py @@ -110,13 +110,10 @@ def test_types_to_csv() -> None: def test_types_to_csv_when_path_passed() -> None: df = pd.DataFrame(data={"col1": [1, 2], "col2": [3, 4]}) - path: Path = Path("./dummy_path.txt") - try: - assert not path.exists() + with ensure_clean() as file: + path = Path(file) df.to_csv(path) df5: pd.DataFrame = pd.read_csv(path) - finally: - path.unlink() def test_types_copy() -> None: @@ -788,16 +785,17 @@ def test_to_markdown() -> None: def test_types_to_feather() -> None: pytest.importorskip("pyarrow") df = pd.DataFrame(data={"col1": [1, 1, 2], "col2": [3, 4, 5]}) - df.to_feather("dummy_path") - # kwargs for pyarrow.feather.write_feather added in 1.1.0 https://pandas.pydata.org/docs/whatsnew/v1.1.0.html - df.to_feather("dummy_path", compression="zstd", compression_level=3, chunksize=2) - - # to_feather has been able to accept a buffer since pandas 1.0.0 - # See https://pandas.pydata.org/docs/whatsnew/v1.0.0.html - # Docstring and type were updated in 1.2.0. - # https://github.com/pandas-dev/pandas/pull/35408 with ensure_clean() as path: df.to_feather(path) + # kwargs for pyarrow.feather.write_feather added in 1.1.0 https://pandas.pydata.org/docs/whatsnew/v1.1.0.html + df.to_feather(path, compression="zstd", compression_level=3, chunksize=2) + + # to_feather has been able to accept a buffer since pandas 1.0.0 + # See https://pandas.pydata.org/docs/whatsnew/v1.0.0.html + # Docstring and type were updated in 1.2.0. + # https://github.com/pandas-dev/pandas/pull/35408 + with open(path, mode="wb") as file: + df.to_feather(file) # compare() method added in 1.1.0 https://pandas.pydata.org/docs/whatsnew/v1.1.0.html diff --git a/tests/test_io.py b/tests/test_io.py index 33a767816..d9f77de43 100644 --- a/tests/test_io.py +++ b/tests/test_io.py @@ -163,43 +163,51 @@ def test_clipboard_iterator(): def test_sas_bdat() -> None: path = pathlib.Path(CWD, "data", "airline.sas7bdat") check(assert_type(read_sas(path), DataFrame), DataFrame) - check( + with check( assert_type(read_sas(path, iterator=True), Union[SAS7BDATReader, XportReader]), SAS7BDATReader, - ) - check( + ): + pass + with check( assert_type(read_sas(path, iterator=True, format="sas7bdat"), SAS7BDATReader), SAS7BDATReader, - ) - check( + ): + pass + with check( assert_type(read_sas(path, chunksize=1), Union[SAS7BDATReader, XportReader]), SAS7BDATReader, - ) - check( + ): + pass + with check( assert_type(read_sas(path, chunksize=1, format="sas7bdat"), SAS7BDATReader), SAS7BDATReader, - ) + ): + pass def test_sas_xport() -> None: path = pathlib.Path(CWD, "data", "SSHSV1_A.xpt") check(assert_type(read_sas(path), DataFrame), DataFrame) - check( + with check( assert_type(read_sas(path, iterator=True), Union[SAS7BDATReader, XportReader]), XportReader, - ) - check( + ): + pass + with check( assert_type(read_sas(path, iterator=True, format="xport"), XportReader), XportReader, - ) - check( + ): + pass + with check( assert_type(read_sas(path, chunksize=1), Union[SAS7BDATReader, XportReader]), XportReader, - ) - check( + ): + pass + with check( assert_type(read_sas(path, chunksize=1, format="xport"), XportReader), XportReader, - ) + ): + pass def test_hdf():