Skip to content

Commit a863e0d

Browse files
committed
Check ndim instead of hashable
1 parent 1fb7564 commit a863e0d

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

pandas/core/base.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -471,12 +471,11 @@ def is_any_frame() -> bool:
471471
try:
472472
result = DataFrame(result)
473473
except ValueError:
474-
475474
# we have a dict of scalars
476475

477-
name = getattr(self, "name", None)
478-
name = name if is_hashable(name) else None
479-
# GH 36212
476+
# GH 36212 use name only if self is a series
477+
name = getattr(self, "name", None) if (self.ndim == 1) else None
478+
480479
result = Series(result, name=name)
481480

482481
return result, True

pandas/tests/frame/apply/test_frame_apply.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1147,7 +1147,7 @@ def test_demo(self):
11471147
)
11481148
tm.assert_frame_equal(result.reindex_like(expected), expected)
11491149

1150-
def test_agg_with_unhashable_name_column_value(self):
1150+
def test_agg_with_name_as_column_name(self):
11511151
# GH 36212 - Column name is "name"
11521152
data = {"name": ["foo", "bar"]}
11531153
df = pd.DataFrame(data)
@@ -1157,7 +1157,7 @@ def test_agg_with_unhashable_name_column_value(self):
11571157
expected = pd.Series({"name": 2})
11581158
tm.assert_series_equal(result, expected)
11591159

1160-
# Check if name is preserved when aggregating series instead
1160+
# Check if name is still preserved when aggregating series instead
11611161
result = df["name"].agg({"name": "count"})
11621162
expected = pd.Series({"name": 2}, name="name")
11631163
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)