Skip to content

Commit f07b76e

Browse files
committed
test: add pandas 2.2 to tests
1 parent 6009cb4 commit f07b76e

File tree

5 files changed

+28
-21
lines changed

5 files changed

+28
-21
lines changed

.github/workflows/CI.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@ jobs:
2121
- '3.9'
2222
- '3.10'
2323
- '3.11'
24+
- '3.12'
2425
pandas-version:
2526
- '2.0.*'
2627
- '2.1.*'
28+
- '2.2.*'
2729
include:
2830
- python-version: '3.8'
2931
pandas-version: '2.0.*'
30-
# https://github.com/pandas-dev/pandas/issues/53665
31-
- python-version: '3.12'
32-
pandas-version: 'none'
3332
# https://github.com/pandas-dev/pandas/issues/42509
3433
- python-version: 'pypy3.8'
3534
pandas-version: 'none'

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ workbook = CalamineWorkbook.from_path("file.xlsx").get_sheet_by_name("Sheet1").t
5050
# ]
5151
```
5252

53-
Also, you can use monkeypatch for pandas for use this library as engine in `read_excel()` (only pandas 2 is supported).
53+
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).
54+
Pandas 2.2 and above have built-in support of python-calamine.
5455
```python
5556
from pandas import read_excel
5657
from python_calamine.pandas import pandas_monkeypatch

python/python_calamine/pandas.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ def __init__(
4949
Arbitrary keyword arguments passed to excel engine.
5050
"""
5151
import_optional_dependency("python_calamine")
52-
if PANDAS_VERSION >= Version("2.1.0"):
52+
if PANDAS_VERSION >= Version("2.2.0"):
53+
raise ValueError("Pandas >= 2.2.0 has builtin support of calamine")
54+
elif PANDAS_VERSION >= Version("2.1.0"):
5355
super().__init__(
5456
filepath_or_buffer,
5557
storage_options=storage_options,

tests/conftest.py

-8
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,6 @@
33
import pytest
44

55

6-
@pytest.fixture
7-
def pandas_monkeypatch():
8-
from python_calamine.pandas import pandas_monkeypatch
9-
10-
pandas_monkeypatch()
11-
yield
12-
13-
146
@pytest.fixture
157
def expected_df_ods():
168
import pandas as pd

tests/test_pandas.py

+21-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
from importlib.metadata import version
12
from pathlib import Path
23

34
import pytest
5+
from packaging.version import Version, parse
46

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

1416

17+
@pytest.fixture(scope="module", autouse=True)
18+
def pandas_monkeypatch():
19+
if parse(version("pandas")) >= Version("2.2.0"):
20+
yield
21+
else:
22+
from python_calamine.pandas import pandas_monkeypatch
23+
24+
pandas_monkeypatch()
25+
yield
26+
27+
1528
@pytest.mark.skipif(not pd, reason="pandas is required")
16-
def test_ods_pandas(pandas_monkeypatch, expected_df_ods):
29+
def test_ods_pandas(expected_df_ods):
1730
result = pd.read_excel(PATH / "base.ods", sheet_name="Sheet1", engine="calamine")
1831

1932
tm.assert_frame_equal(result, expected_df_ods)
2033

2134

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

3952

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

4457
tm.assert_frame_equal(result, expected_df_excel)
4558

4659

4760
@pytest.mark.skipif(not pd, reason="pandas is required")
48-
def test_xls_xlrd_pandas(pandas_monkeypatch):
61+
def test_xls_xlrd_pandas():
4962
result_calamine = pd.read_excel(
5063
PATH / "base.xls", sheet_name="Sheet1", engine="calamine"
5164
)
@@ -63,14 +76,14 @@ def test_xls_xlrd_pandas(pandas_monkeypatch):
6376

6477

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

6982
tm.assert_frame_equal(result, expected_df_excel)
7083

7184

7285
@pytest.mark.skipif(not pd, reason="pandas is required")
73-
def test_xlsb_pyxlsb_pandas(pandas_monkeypatch):
86+
def test_xlsb_pyxlsb_pandas():
7487
result_calamine = pd.read_excel(
7588
PATH / "base.xlsb", sheet_name="Sheet1", engine="calamine"
7689
)
@@ -88,14 +101,14 @@ def test_xlsb_pyxlsb_pandas(pandas_monkeypatch):
88101

89102

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

94107
tm.assert_frame_equal(result, expected_df_excel)
95108

96109

97110
@pytest.mark.skipif(not pd, reason="pandas is required")
98-
def test_xlsb_openpyxl_pandas(pandas_monkeypatch):
111+
def test_xlsb_openpyxl_pandas():
99112
result_calamine = pd.read_excel(
100113
PATH / "base.xlsx", sheet_name="Sheet1", engine="calamine"
101114
)

0 commit comments

Comments
 (0)