Skip to content

Commit 4e72340

Browse files
authored
BUG: Fix pyarrow groupby tests (#48443)
1 parent 191557d commit 4e72340

File tree

2 files changed

+11
-34
lines changed

2 files changed

+11
-34
lines changed

pandas/core/series.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,10 @@ def _set_axis(self, axis: int, labels: AnyArrayLike | list) -> None:
573573
"""
574574
labels = ensure_index(labels)
575575

576-
if labels._is_all_dates:
576+
if labels._is_all_dates and not (
577+
type(labels) is Index and not isinstance(labels.dtype, np.dtype)
578+
):
579+
# exclude e.g. timestamp[ns][pyarrow] dtype from this casting
577580
deep_labels = labels
578581
if isinstance(labels, CategoricalIndex):
579582
deep_labels = labels.categories

pandas/tests/extension/test_arrow.py

+7-33
Original file line numberDiff line numberDiff line change
@@ -516,15 +516,6 @@ def test_groupby_extension_no_sort(self, data_for_grouping, request):
516516
reason=f"pyarrow doesn't support factorizing {pa_dtype}",
517517
)
518518
)
519-
elif pa.types.is_date(pa_dtype) or (
520-
pa.types.is_timestamp(pa_dtype) and pa_dtype.tz is None
521-
):
522-
request.node.add_marker(
523-
pytest.mark.xfail(
524-
raises=AttributeError,
525-
reason="GH 34986",
526-
)
527-
)
528519
super().test_groupby_extension_no_sort(data_for_grouping)
529520

530521
def test_groupby_extension_transform(self, data_for_grouping, request):
@@ -551,8 +542,7 @@ def test_groupby_extension_apply(
551542
self, data_for_grouping, groupby_apply_op, request
552543
):
553544
pa_dtype = data_for_grouping.dtype.pyarrow_dtype
554-
# Is there a better way to get the "series" ID for groupby_apply_op?
555-
is_series = "series" in request.node.nodeid
545+
# TODO: Is there a better way to get the "object" ID for groupby_apply_op?
556546
is_object = "object" in request.node.nodeid
557547
if pa.types.is_duration(pa_dtype):
558548
request.node.add_marker(
@@ -571,13 +561,6 @@ def test_groupby_extension_apply(
571561
reason="GH 47514: _concat_datetime expects axis arg.",
572562
)
573563
)
574-
elif not is_series:
575-
request.node.add_marker(
576-
pytest.mark.xfail(
577-
raises=AttributeError,
578-
reason="GH 34986",
579-
)
580-
)
581564
with tm.maybe_produces_warning(
582565
PerformanceWarning, pa_version_under7p0, check_stacklevel=False
583566
):
@@ -610,16 +593,6 @@ def test_groupby_extension_agg(self, as_index, data_for_grouping, request):
610593
reason=f"pyarrow doesn't support factorizing {pa_dtype}",
611594
)
612595
)
613-
elif as_index is True and (
614-
pa.types.is_date(pa_dtype)
615-
or (pa.types.is_timestamp(pa_dtype) and pa_dtype.tz is None)
616-
):
617-
request.node.add_marker(
618-
pytest.mark.xfail(
619-
raises=AttributeError,
620-
reason="GH 34986",
621-
)
622-
)
623596
with tm.maybe_produces_warning(
624597
PerformanceWarning, pa_version_under7p0, check_stacklevel=False
625598
):
@@ -1464,12 +1437,13 @@ def test_diff(self, data, periods, request):
14641437
@pytest.mark.parametrize("dropna", [True, False])
14651438
def test_value_counts(self, all_data, dropna, request):
14661439
pa_dtype = all_data.dtype.pyarrow_dtype
1467-
if pa.types.is_date(pa_dtype) or (
1468-
pa.types.is_timestamp(pa_dtype) and pa_dtype.tz is None
1469-
):
1440+
if (
1441+
pa.types.is_date(pa_dtype)
1442+
or (pa.types.is_timestamp(pa_dtype) and pa_dtype.tz is None)
1443+
) and dropna:
14701444
request.node.add_marker(
14711445
pytest.mark.xfail(
1472-
raises=AttributeError,
1446+
raises=NotImplementedError, # tries casting to i8
14731447
reason="GH 34986",
14741448
)
14751449
)
@@ -1489,7 +1463,7 @@ def test_value_counts_with_normalize(self, data, request):
14891463
):
14901464
request.node.add_marker(
14911465
pytest.mark.xfail(
1492-
raises=AttributeError,
1466+
raises=NotImplementedError, # tries casting to i8
14931467
reason="GH 34986",
14941468
)
14951469
)

0 commit comments

Comments
 (0)