8000 CI: Test Python 3.12 by lithomas1 · Pull Request #53743 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

CI: Test Python 3.12 #53743

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 29 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ff98491
CI: Test Python 3.12
lithomas1 Jun 20, 2023
fcbe1ed
Update unit-tests.yml
lithomas1 Jun 20, 2023
dd4a488
Update config.yml
lithomas1 Jun 20, 2023
c809bcd
update
lithomas1 Jun 20, 2023
cf7e272
Merge branch 'main' into test-py312
lithomas1 Jun 20, 2023
8c7aea2
fix condition
lithomas1 Jun 20, 2023
dc88fa8
Merge branch 'main' of https://github.com/pandas-dev/pandas into test…
lithomas1 Jun 25, 2023
d2b3868
fix some tests
lithomas1 Jun 25, 2023
5814bcc
Remove wheel building for Python 3.12
lithomas1 Jun 25, 2023
7be7ea9
fix more
lithomas1 Jun 26, 2023
e9c0ed4
Use timezone.utc
mroeschke Jun 29, 2023
f735b8c
Merge remote-tracking branch 'upstream/main' into test-py312
mroeschke Jun 29, 2023
80d31e1
Merge branch 'main' into test-py312
mroeschke Jul 7, 2023
b8f351d
Address typing, utcfromtimestamp
mroeschke Jul 8000 7, 2023
7cbfd7c
fix some slice changes
lithomas1 Jul 12, 2023
e507d45
fix all indexing bugs?
lithomas1 Jul 14, 2023
90dbdeb
fix import
lithomas1 Jul 14, 2023
5e421f3
go for green
lithomas1 Jul 14, 2023
0e04fd2
disable macos for now, fix other tests
lithomas1 Jul 14, 2023
b5ae510
Update indexing.py
lithomas1 Jul 14, 2023
b1182ac
finally fix?
lithomas1 Jul 14, 2023
ddae8f8
Merge branch 'main' into test-py312
lithomas1 Jul 14, 2023
64e12a9
Update expr.py
lithomas1 Jul 17, 2023
bc64b47
Merge branch 'main' into test-py312
lithomas1 Jul 24, 2023
2c1755e
Update pandas/tests/computation/test_eval.py
lithomas1 Jul 24, 2023
5dfc14b
Update test_eval.py
lithomas1 Jul 25, 2023
a1bd210
Update test_eval.py
lithomas1 Jul 25, 2023
298f31b
fixes
lithomas1 Jul 25, 2023
88a0cb8
formatting
lithomas1 Jul 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
8000
Diff view
Prev Previous commit
Next Next commit
fix all indexing bugs?
  • Loading branch information
lithomas1 committed Jul 14, 2023
commit e507d454496db14148caeee1d2c082717985e0e9
2 changes: 2 additions & 0 deletions pandas/compat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
ISMUSL,
PY310,
PY311,
PY312,
PYPY,
)
import pandas.compat.compressors
Expand Down Expand Up @@ -164,5 +165,6 @@ def get_lzma_file() -> type[pandas.compat.compressors.LZMAFile]:
"ISMUSL",
"PY310",
"PY311",
"PY312",
"PYPY",
]
2 changes: 2 additions & 0 deletions pandas/compat/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

PY310 = sys.version_info >= (3, 10)
PY311 = sys.version_info >= (3, 11)
PY312 = sys.version_info >= (3, 12)
PYPY = platform.python_implementation() == "PyPy"
ISMUSL = "musl" in (sysconfig.get_config_var("HOST_GNU_TYPE") or "")

Expand All @@ -24,5 +25,6 @@
"ISMUSL",
"PY310",
"PY311",
"PY312",
"PYPY",
]
5 changes: 5 additions & 0 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3784,6 +3784,11 @@ def get_loc(self, key):
try:
return self._engine.get_loc(casted_key)
except KeyError as err:
if isinstance(casted_key, slice) or (
isinstance(casted_key, Iterable)
and any(isinstance(x, slice) for x in casted_key)
):
raise InvalidIndexError(key)
raise KeyError(key) from err
except TypeError:
# If we have a listlike key, _check_indexing_error will raise
Expand Down
34 changes: 31 additions & 3 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,12 @@ def _get_setitem_indexer(self, key):

ax = self.obj._get_axis(0)

if isinstance(ax, MultiIndex) and self.name != "iloc" and is_hashable(key):
if (
isinstance(ax, MultiIndex)
and self.name != "iloc"
and is_hashable(key)
and not isinstance(key, slice)
):
with suppress(KeyError, InvalidIndexError):
# TypeError e.g. passed a bool
return ax.get_loc(key)
Expand Down Expand Up @@ -1060,6 +1065,16 @@ def _getitem_nested_tuple(self, tup: tuple):
# we have a nested tuple so have at least 1 multi-index level
# we should be able to match up the dimensionality here

def _contains_slice(x: object) -> bool:
# Check if object is a slice or a tuple containing a slice
if isinstance(x, tuple):
for v in x:
if isinstance(v, slice):
return True
elif isinstance(x, slice):
return True
return False

for key in tup:
check_dict_or_set_indexers(key)

Expand All @@ -1070,7 +1085,10 @@ def _getitem_nested_tuple(self, tup: tuple):
if self.name != "loc":
# This should never be reached, but let's be explicit about it
raise ValueError("Too many indices") # pragma: no cover
if all(is_hashable(x) or com.is_null_slice(x) for x in tup):
if all(
(is_hashable(x) and not _contains_slice(x)) or com.is_null_slice(x)
for x in tup
):
# GH#10521 Series should reduce MultiIndex dimensions instead of
# DataFrame, IndexingError is not raised when slice(None,None,None)
# with one row.
Expand Down Expand Up @@ -1419,7 +1437,17 @@ def _convert_to_indexer(self, key, axis: AxisInt):
):
raise IndexingError("Too many indexers")

if is_scalar(key) or (isinstance(labels, MultiIndex) and is_hashable(key)):
# Slices are not valid keys passed in by the user,
# even though they are hashable in Python 3.12
contains_slice = False
if isinstance(key, tuple):
for v in key:
if isinstance(v, slice):
contains_slice = True

if is_scalar(key) or (
isinstance(labels, MultiIndex) and is_hashable(key) and not contains_slice
):
# Otherwise get_loc will raise InvalidIndexError

# if we are a label return me
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,7 @@ def __getitem__(self, key):
elif key_is_scalar:
return self._get_value(key)

if is_hashable(key):
if is_hashable(key) and not isinstance(key, slice):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very late review comment: would it make sense to make is_hashable_non_slice or something? it wouldn't surprise me if many places that use is_hashable current assume non-slice but didn't get updated by this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah sure, I just updated the places that broke in the tests.

Is there a case where we would actually want is_hashable for a slice to equal True, though?
(I was thinking it might be cleaner to make is_hashable always return False for slices. This would be a breaking API change, though).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think having is_hashable be anything other than a try/except around hash would cause problems. im suggesting a new function to de-duplicate the hashable-but-not-slice checks this introduces

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made an issue #55152.

I don't have the same time that I had in summer to work on pandas, but I'll try to have a look (no promises, though).

# Otherwise index.get_value will raise InvalidIndexError
try:
# For labels that don't resolve as scalars like tuples and frozensets
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/series/indexing/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ def test_basic_getitem_setitem_corner(datetime_series):
# OK
msg = r"unhashable type(: 'slice')?"
with pytest.raises(TypeError, match=msg):
datetime_series[[5, slice(None, None)]]
datetime_series[[5, [None, None]]]
with pytest.raises(TypeError, match=msg):
datetime_series[[5, slice(None, None)]] = 2
datetime_series[[5, [None, None]]] = 2


def test_slice(string_series, object_series, using_copy_on_write):
Expand Down
0