Skip to content

Commit

Permalink
test: add pandas 2.2 to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dimastbk committed Jan 20, 2024
1 parent 6009cb4 commit 68e6035
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 21 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ jobs:
- '3.9'
- '3.10'
- '3.11'
- '3.12'
pandas-version:
- '2.0.*'
- '2.1.*'
- '2.2.*'
include:
- python-version: '3.8'
pandas-version: '2.0.*'
# https://github.com/pandas-dev/pandas/issues/53665
- python-version: '3.12'
pandas-version: 'none'
# https://github.com/pandas-dev/pandas/issues/42509
- python-version: 'pypy3.8'
pandas-version: 'none'
Expand All @@ -39,6 +38,9 @@ jobs:
# https://github.com/pandas-dev/pandas/issues/42509
- python-version: 'pypy3.10'
pandas-version: 'none'
exclude:
- python-version: '3.12'
pandas-version: '2.2.*'

runs-on: ubuntu-latest

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ workbook = CalamineWorkbook.from_path("file.xlsx").get_sheet_by_name("Sheet1").t
# ]
```

Also, you can use monkeypatch for pandas for use this library as engine in `read_excel()` (only pandas 2 is supported).
Also, you can use monkeypatch for pandas for use this library as engine in `read_excel()` (only pandas 2.0 and 2.1 are supported).
Pandas 2.2 and above have built-in support of python-calamine.
```python
from pandas import read_excel
from python_calamine.pandas import pandas_monkeypatch
Expand Down
4 changes: 3 additions & 1 deletion python/python_calamine/pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ def __init__(
Arbitrary keyword arguments passed to excel engine.
"""
import_optional_dependency("python_calamine")
if PANDAS_VERSION >= Version("2.1.0"):
if PANDAS_VERSION >= Version("2.2.0"):
raise ValueError("Pandas >= 2.2.0 has builtin support of calamine")
elif PANDAS_VERSION >= Version("2.1.0"):
super().__init__(
filepath_or_buffer,
storage_options=storage_options,
Expand Down
8 changes: 0 additions & 8 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@
import pytest


@pytest.fixture
def pandas_monkeypatch():
from python_calamine.pandas import pandas_monkeypatch

pandas_monkeypatch()
yield


@pytest.fixture
def expected_df_ods():
import pandas as pd
Expand Down
29 changes: 21 additions & 8 deletions tests/test_pandas.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from importlib.metadata import version
from pathlib import Path

import pytest
from packaging.version import Version, parse

try:
import pandas as pd
Expand All @@ -12,16 +14,27 @@
PATH = Path(__file__).parent / "data"


@pytest.fixture(scope="module", autouse=True)
def pandas_monkeypatch():
if parse(version("pandas")) >= Version("2.2.0"):
yield
else:
from python_calamine.pandas import pandas_monkeypatch

pandas_monkeypatch()
yield


@pytest.mark.skipif(not pd, reason="pandas is required")
def test_ods_pandas(pandas_monkeypatch, expected_df_ods):
def test_ods_pandas(expected_df_ods):
result = pd.read_excel(PATH / "base.ods", sheet_name="Sheet1", engine="calamine")

tm.assert_frame_equal(result, expected_df_ods)


@pytest.mark.skipif(not pd, reason="pandas is required")
@pytest.mark.xfail(reason="OdfReader can't parse timedelta")
def test_ods_odfpy_pandas(pandas_monkeypatch):
def test_ods_odfpy_pandas():
result_calamine = pd.read_excel(
PATH / "base.ods", sheet_name="Sheet1", engine="calamine"
)
Expand All @@ -38,14 +51,14 @@ def test_ods_odfpy_pandas(pandas_monkeypatch):


@pytest.mark.skipif(not pd, reason="pandas is required")
def test_xls_pandas(pandas_monkeypatch, expected_df_excel):
def test_xls_pandas(expected_df_excel):
result = pd.read_excel(PATH / "base.xls", sheet_name="Sheet1", engine="calamine")

tm.assert_frame_equal(result, expected_df_excel)


@pytest.mark.skipif(not pd, reason="pandas is required")
def test_xls_xlrd_pandas(pandas_monkeypatch):
def test_xls_xlrd_pandas():
result_calamine = pd.read_excel(
PATH / "base.xls", sheet_name="Sheet1", engine="calamine"
)
Expand All @@ -63,14 +76,14 @@ def test_xls_xlrd_pandas(pandas_monkeypatch):


@pytest.mark.skipif(not pd, reason="pandas is required")
def test_xlsb_pandas(pandas_monkeypatch, expected_df_excel):
def test_xlsb_pandas(expected_df_excel):
result = pd.read_excel(PATH / "base.xlsb", sheet_name="Sheet1", engine="calamine")

tm.assert_frame_equal(result, expected_df_excel)


@pytest.mark.skipif(not pd, reason="pandas is required")
def test_xlsb_pyxlsb_pandas(pandas_monkeypatch):
def test_xlsb_pyxlsb_pandas():
result_calamine = pd.read_excel(
PATH / "base.xlsb", sheet_name="Sheet1", engine="calamine"
)
Expand All @@ -88,14 +101,14 @@ def test_xlsb_pyxlsb_pandas(pandas_monkeypatch):


@pytest.mark.skipif(not pd, reason="pandas is required")
def test_xlsx_pandas(pandas_monkeypatch, expected_df_excel):
def test_xlsx_pandas(expected_df_excel):
result = pd.read_excel(PATH / "base.xlsx", sheet_name="Sheet1", engine="calamine")

tm.assert_frame_equal(result, expected_df_excel)


@pytest.mark.skipif(not pd, reason="pandas is required")
def test_xlsb_openpyxl_pandas(pandas_monkeypatch):
def test_xlsb_openpyxl_pandas():
result_calamine = pd.read_excel(
PATH / "base.xlsx", sheet_name="Sheet1", engine="calamine"
)
Expand Down

0 comments on commit 68e6035

Please sign in to comment.