Skip to content

Commit c499562

Browse files
fangchenlilithomas1
authored andcommitted
CI: start testing Python 3.11 (pandas-dev#47442)
* CI: start testing Python 3.11 * fix * fix * fix macos * add error msg compat * fix error msg in test * xfail and skip tests * fix error * roll back * revert * maybe fix errors * update * try something * pin hypothesis * Don't check parentheses equality * typo * pin cython * correctly pin hypothesis * adjust test * remove compiler flag * typo'ed * fix tests * linter * clarify freeze/unfreeze instructions * whitespace * one more Co-authored-by: Thomas Li <[email protected]>
1 parent 2fa900a commit c499562

File tree

8 files changed

+81
-26
lines changed

8 files changed

+81
-26
lines changed

.github/workflows/python-dev.yml

+29-17
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
1-
# This file is purposely frozen(does not run). DO NOT DELETE IT
2-
# Unfreeze(by commentingthe if: false() condition) once the
3-
# next Python Dev version has released beta 1 and both Cython and numpy support it
4-
# After that Python has released, migrate the workflows to the
5-
# posix GHA workflows and "freeze" this file by
6-
# uncommenting the if: false() condition
1+
# This workflow may or may not run depending on the state of the next
2+
# unreleased Python version. DO NOT DELETE IT.
3+
#
4+
# In general, this file will remain frozen(present, but not running) until:
5+
# - The next unreleased Python version has released beta 1
6+
# - This version should be available on Github Actions.
7+
# - Our required build/runtime dependencies(numpy, pytz, Cython, python-dateutil)
8+
# support that unreleased Python version.
9+
# To unfreeze, comment out the ``if: false`` condition, and make sure you update
10+
# the name of the workflow and Python version in actions/setup-python to: '3.12-dev'
11+
#
12+
# After it has been unfrozen, this file should remain unfrozen(present, and running) until:
13+
# - The next Python version has been officially released.
14+
# OR
15+
# - Most/All of our optional dependencies support Python 3.11 AND
16+
# - The next Python version has released a rc(we are guaranteed a stable ABI).
17+
# To freeze this file, uncomment out the ``if: false`` condition, and migrate the jobs
18+
# to the corresponding posix/windows-macos/sdist etc. workflows.
719
# Feel free to modify this comment as necessary.
820

921
name: Python Dev
@@ -32,7 +44,7 @@ permissions:
3244

3345
jobs:
3446
build:
35-
if: false # Comment this line out to "unfreeze"
47+
# if: false # Uncomment this to freeze the workflow, comment it to unfreeze
3648
runs-on: ${{ matrix.os }}
3749
strategy:
3850
fail-fast: false
@@ -53,27 +65,27 @@ jobs:
5365
fetch-depth: 0
5466

5567
- name: Set up Python Dev Version
56-
uses: actions/setup-python@v3
68+
uses: actions/setup-python@v4
5769
with:
5870
python-version: '3.11-dev'
5971

6072
- name: Install dependencies
61-
shell: bash -el {0}
6273
run: |
63-
python3 -m pip install --upgrade pip setuptools wheel
64-
python3 -m pip install -i https://pypi.anaconda.org/scipy-wheels-nightly/simple numpy
65-
python3 -m pip install git+https://github.com/nedbat/coveragepy.git
66-
python3 -m pip install cython python-dateutil pytz hypothesis pytest>=6.2.5 pytest-xdist pytest-cov pytest-asyncio>=0.17
67-
python3 -m pip list
74+
python --version
75+
python -m pip install --upgrade pip setuptools wheel
76+
python -m pip install git+https://github.com/numpy/numpy.git
77+
python -m pip install git+https://github.com/nedbat/coveragepy.git
78+
python -m pip install python-dateutil pytz cython hypothesis==6.52.1 pytest>=6.2.5 pytest-xdist pytest-cov pytest-asyncio>=0.17
79+
python -m pip list
6880
6981
- name: Build Pandas
7082
run: |
71-
python3 setup.py build_ext -q -j2
72-
python3 -m pip install -e . --no-build-isolation --no-use-pep517
83+
python setup.py build_ext -q -j2
84+
python -m pip install -e . --no-build-isolation --no-use-pep517
7385
7486
- name: Build Version
7587
run: |
76-
python3 -c "import pandas; pandas.show_versions();"
88+
python -c "import pandas; pandas.show_versions();"
7789
7890
- name: Test
7991
uses: ./.github/actions/run-tests

pandas/compat/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
PY39 = sys.version_info >= (3, 9)
3838
PY310 = sys.version_info >= (3, 10)
39+
PY311 = sys.version_info >= (3, 11)
3940
PYPY = platform.python_implementation() == "PyPy"
4041
IS64 = sys.maxsize > 2**32
4142

pandas/tests/arrays/categorical/test_api.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import numpy as np
44
import pytest
55

6+
from pandas.compat import PY311
7+
68
from pandas import (
79
Categorical,
810
CategoricalIndex,
@@ -61,7 +63,11 @@ def test_set_ordered(self):
6163
assert not cat2.ordered
6264

6365
# removed in 0.19.0
64-
msg = "can't set attribute"
66+
msg = (
67+
"property 'ordered' of 'Categorical' object has no setter"
68+
if PY311
69+
else "can't set attribute"
70+
)
6571
with pytest.raises(AttributeError, match=msg):
6672
cat.ordered = True
6773
with pytest.raises(AttributeError, match=msg):
@@ -515,7 +521,12 @@ def test_codes_immutable(self):
515521
tm.assert_numpy_array_equal(c.codes, exp)
516522

517523
# Assignments to codes should raise
518-
with pytest.raises(AttributeError, match="can't set attribute"):
524+
msg = (
525+
"property 'codes' of 'Categorical' object has no setter"
526+
if PY311
527+
else "can't set attribute"
528+
)
529+
with pytest.raises(AttributeError, match=msg):
519530
c.codes = np.array([0, 1, 2, 0, 1], dtype="int8")
520531

521532
# changes in the codes array should raise

pandas/tests/indexes/datetimes/test_constructors.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,10 @@ def test_timestamp_constructor_retain_fold(tz, fold):
11371137

11381138
_tzs = ["dateutil/Europe/London"]
11391139
if PY39:
1140-
_tzs = ["dateutil/Europe/London", zoneinfo.ZoneInfo("Europe/London")]
1140+
try:
1141+
_tzs = ["dateutil/Europe/London", zoneinfo.ZoneInfo("Europe/London")]
1142+
except zoneinfo.ZoneInfoNotFoundError:
1143+
pass
11411144

11421145

11431146
@pytest.mark.parametrize("tz", _tzs)

pandas/tests/indexes/multi/test_get_set.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import numpy as np
22
import pytest
33

4+
from pandas.compat import PY311
5+
46
from pandas.core.dtypes.dtypes import DatetimeTZDtype
57

68
import pandas as pd
@@ -139,9 +141,15 @@ def test_set_levels_codes_directly(idx):
139141
minor_codes = [(x + 1) % 1 for x in minor_codes]
140142
new_codes = [major_codes, minor_codes]
141143

142-
msg = "[Cc]an't set attribute"
144+
msg = "Can't set attribute"
143145
with pytest.raises(AttributeError, match=msg):
144146
idx.levels = new_levels
147+
148+
msg = (
149+
"property 'codes' of 'MultiIndex' object has no setter"
150+
if PY311
151+
else "can't set attribute"
152+
)
145153
with pytest.raises(AttributeError, match=msg):
146154
idx.codes = new_codes
147155

pandas/tests/indexes/period/test_freq_attr.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import pytest
22

3+
from pandas.compat import PY311
4+
35
from pandas import (
46
offsets,
57
period_range,
@@ -17,5 +19,10 @@ def test_freq_setter_deprecated(self):
1719
idx.freq
1820

1921
# warning for setter
20-
with pytest.raises(AttributeError, match="can't set attribute"):
22+
msg = (
23+
"property 'freq' of 'PeriodArray' object has no setter"
24+
if PY311
25+
else "can't set attribute"
26+
)
27+
with pytest.raises(AttributeError, match=msg):
2128
idx.freq = offsets.Day()

pandas/tests/io/parser/common/test_read_errors.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import numpy as np
1313
import pytest
1414

15+
from pandas.compat import PY311
1516
from pandas.errors import (
1617
EmptyDataError,
1718
ParserError,
@@ -224,13 +225,19 @@ def test_read_csv_wrong_num_columns(all_parsers):
224225
parser.read_csv(StringIO(data))
225226

226227

227-
def test_null_byte_char(all_parsers):
228+
def test_null_byte_char(request, all_parsers):
228229
# see gh-2741
229230
data = "\x00,foo"
230231
names = ["a", "b"]
231232
parser = all_parsers
232233

233-
if parser.engine == "c":
234+
if parser.engine == "c" or (parser.engine == "python" and PY311):
235+
if parser.engine == "python" and PY311:
236+
request.node.add_marker(
237+
pytest.mark.xfail(
238+
reason="In Python 3.11, this is read as an empty character not null"
239+
)
240+
)
234241
expected = DataFrame([[np.nan, "foo"]], columns=names)
235242
out = parser.read_csv(StringIO(data), names=names)
236243
tm.assert_frame_equal(out, expected)

pandas/tests/io/parser/test_quoting.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import pytest
1010

11+
from pandas.compat import PY311
1112
from pandas.errors import ParserError
1213

1314
from pandas import DataFrame
@@ -80,11 +81,16 @@ def test_null_quote_char(all_parsers, quoting, quote_char):
8081

8182
if quoting != csv.QUOTE_NONE:
8283
# Sanity checking.
83-
msg = "quotechar must be set if quoting enabled"
84+
msg = (
85+
'"quotechar" must be a 1-character string'
86+
if PY311 and all_parsers.engine == "python" and quote_char == ""
87+
else "quotechar must be set if quoting enabled"
88+
)
8489

8590
with pytest.raises(TypeError, match=msg):
8691
parser.read_csv(StringIO(data), **kwargs)
87-
else:
92+
elif not (PY311 and all_parsers.engine == "python"):
93+
# Python 3.11+ doesn't support null/blank quote chars in their csv parsers
8894
expected = DataFrame([[1, 2, 3]], columns=["a", "b", "c"])
8995
result = parser.read_csv(StringIO(data), **kwargs)
9096
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)