Skip to content

Commit 1a2e017

Browse files
committed
groupby tests
1 parent 33b95df commit 1a2e017

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

pandas/core/internals/blocks.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1762,7 +1762,7 @@ def _try_cast_result(self, result, dtype=None):
17621762
try:
17631763

17641764
result = self._holder._from_sequence(
1765-
np.asarray(result).ravel(), dtype=dtype)
1765+
result.ravel(), dtype=dtype)
17661766
except Exception:
17671767
pass
17681768

pandas/tests/extension/base/groupby.py

+12
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,18 @@ def test_groupby_extension_apply(
6464
df.groupby("A").apply(groupby_apply_op)
6565
df.groupby("A").B.apply(groupby_apply_op)
6666

67+
def test_groupby_apply_identity(self, data_for_grouping):
68+
df = pd.DataFrame({"A": [1, 1, 2, 2, 3, 3, 1, 4],
69+
"B": data_for_grouping})
70+
result = df.groupby('A').B.apply(lambda x: x.array)
71+
expected = pd.Series([df.B.iloc[[0, 1, 6]].array,
72+
df.B.iloc[[2, 3]].array,
73+
df.B.iloc[[4, 5]].array,
74+
df.B.iloc[[7]].array],
75+
index=pd.Index([1, 2, 3, 4], name='A'),
76+
name='B')
77+
self.assert_series_equal(result, expected)
78+
6779
def test_in_numeric_groupby(self, data_for_grouping):
6880
df = pd.DataFrame({"A": [1, 1, 2, 2, 3, 3, 1, 4],
6981
"B": data_for_grouping,

pandas/tests/extension/decimal/test_decimal.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,11 @@ class TestCasting(BaseDecimal, base.BaseCastingTests):
192192

193193

194194
class TestGroupby(BaseDecimal, base.BaseGroupbyTests):
195-
pass
195+
196+
@pytest.mark.xfail(
197+
reason="needs to correctly define __eq__ to handle nans, xref #27081.")
198+
def test_groupby_apply_identity(self, data_for_grouping):
199+
super().test_groupby_apply_idendeity(data_for_grouping)
196200

197201

198202
class TestSetitem(BaseDecimal, base.BaseSetitemTests):

0 commit comments

Comments
 (0)