Skip to content

Commit da1a8bb

Browse files
committed
Merge branch 'main' into depr-unit
2 parents f2cb5de + 1028791 commit da1a8bb

File tree

6 files changed

+28
-26
lines changed

6 files changed

+28
-26
lines changed

doc/source/whatsnew/v3.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,7 @@ Bug fixes
934934
Categorical
935935
^^^^^^^^^^^
936936
- Bug in :func:`Series.apply` where ``nan`` was ignored for :class:`CategoricalDtype` (:issue:`59938`)
937+
- Bug in :func:`testing.assert_index_equal` raising ``TypeError`` instead of ``AssertionError`` for incomparable ``CategoricalIndex`` when ``check_categorical=True`` and ``exact=False`` (:issue:`61935`)
937938
- Bug in :meth:`Categorical.astype` where ``copy=False`` would still trigger a copy of the codes (:issue:`62000`)
938939
- Bug in :meth:`DataFrame.pivot` and :meth:`DataFrame.set_index` raising an ``ArrowNotImplementedError`` for columns with pyarrow dictionary dtype (:issue:`53051`)
939940
- Bug in :meth:`Series.convert_dtypes` with ``dtype_backend="pyarrow"`` where empty :class:`CategoricalDtype` :class:`Series` raised an error or got converted to ``null[pyarrow]`` (:issue:`59934`)

pandas/_testing/asserters.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,17 @@ def _check_types(left, right, obj: str = "Index") -> None:
325325
# skip exact index checking when `check_categorical` is False
326326
elif check_exact and check_categorical:
327327
if not left.equals(right):
328-
mismatch = left._values != right._values
328+
# _values compare can raise TypeError (non-comparable
329+
# categoricals (GH#61935)
330+
try:
331+
mismatch = left._values != right._values
332+
except TypeError:
333+
raise_assert_detail(
334+
obj,
335+
"types are not comparable (non-matching categorical categories)",
336+
left,
337+
right,
338+
)
329339

330340
if not isinstance(mismatch, np.ndarray):
331341
mismatch = cast("ExtensionArray", mismatch).fillna(True)

pandas/tests/io/excel/test_style.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import contextlib
2-
import time
32
import uuid
43

54
import numpy as np
@@ -324,18 +323,10 @@ def test_styler_to_s3(s3_bucket_public, s3so):
324323
target_file = f"{uuid.uuid4()}.xlsx"
325324
df = DataFrame({"x": [1, 2, 3], "y": [2, 4, 6]})
326325
styler = df.style.set_sticky(axis="index")
327-
styler.to_excel(f"s3://{mock_bucket_name}/{target_file}", storage_options=s3so)
328-
timeout = 5
329-
while True:
330-
if target_file in (obj.key for obj in s3_bucket_public.objects.all()):
331-
break
332-
time.sleep(0.1)
333-
timeout -= 0.1
334-
assert timeout > 0, "Timed out waiting for file to appear on moto"
335-
result = read_excel(
336-
f"s3://{mock_bucket_name}/{target_file}", index_col=0, storage_options=s3so
337-
)
338-
tm.assert_frame_equal(result, df)
326+
uri = f"s3://{mock_bucket_name}/{target_file}"
327+
styler.to_excel(uri, storage_options=s3so)
328+
result = read_excel(uri, index_col=0, storage_options=s3so)
329+
tm.assert_frame_equal(result, df)
339330

340331

341332
@pytest.mark.parametrize("merge_cells", [True, False, "columns"])

pandas/tests/io/json/test_pandas.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import json
88
import os
99
import sys
10-
import time
1110
import uuid
1211

1312
import numpy as np
@@ -2019,14 +2018,10 @@ def test_to_s3(self, s3_bucket_public, s3so):
20192018
mock_bucket_name = s3_bucket_public.name
20202019
target_file = f"{uuid.uuid4()}.json"
20212020
df = DataFrame({"x": [1, 2, 3], "y": [2, 4, 6]})
2022-
df.to_json(f"s3://{mock_bucket_name}/{target_file}", storage_options=s3so)
2023-
timeout = 5
2024-
while True:
2025-
if target_file in (obj.key for obj in s3_bucket_public.objects.all()):
2026-
break
2027-
time.sleep(0.1)
2028-
timeout -= 0.1
2029-
assert timeout > 0, "Timed out waiting for file to appear on moto"
2021+
uri = f"s3://{mock_bucket_name}/{target_file}"
2022+
df.to_json(uri, storage_options=s3so)
2023+
result = read_json(uri, storage_options=s3so)
2024+
tm.assert_frame_equal(result, df)
20302025

20312026
def test_json_pandas_nulls(self, nulls_fixture):
20322027
# GH 31615

pandas/tests/io/test_compression.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import sys
66
import tarfile
77
import textwrap
8-
import time
98
import zipfile
109

1110
import numpy as np
@@ -193,7 +192,6 @@ def test_gzip_reproducibility_file_name(temp_file):
193192
# test for filename
194193
path = temp_file
195194
df.to_csv(path, compression=compression_options)
196-
time.sleep(0.1)
197195
output = path.read_bytes()
198196
df.to_csv(path, compression=compression_options)
199197
assert output == path.read_bytes()
@@ -216,7 +214,6 @@ def test_gzip_reproducibility_file_object():
216214
buffer = io.BytesIO()
217215
df.to_csv(buffer, compression=compression_options, mode="wb")
218216
output = buffer.getvalue()
219-
time.sleep(0.1)
220217
buffer = io.BytesIO()
221218
df.to_csv(buffer, compression=compression_options, mode="wb")
222219
assert output == buffer.getvalue()

pandas/tests/util/test_assert_index_equal.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,3 +317,11 @@ def test_assert_multi_index_dtype_check_categorical(check_categorical):
317317
tm.assert_index_equal(idx1, idx2, check_categorical=check_categorical)
318318
else:
319319
tm.assert_index_equal(idx1, idx2, check_categorical=check_categorical)
320+
321+
322+
def test_assert_index_equal_categorical_incomparable_categories():
323+
# GH#61935
324+
left = Index([1, 2, 3], name="a", dtype="category")
325+
right = Index([1, 2, 6], name="a", dtype="category")
326+
with pytest.raises(AssertionError, match="types are not comparable"):
327+
tm.assert_index_equal(left, right, check_categorical=True, exact=False)

0 commit comments

Comments
 (0)