@@ -233,6 +233,36 @@ def test_apply_issues(self):
233
233
lambda x : x ['time' ][x ['value' ].idxmax ()])
234
234
assert_series_equal (result , expected )
235
235
236
+ def test_apply_trivial (self ):
237
+ # GH 20066
238
+ # trivial apply: ignore input and return a constant dataframe.
239
+ df = pd .DataFrame ({'key' : ['a' , 'a' , 'b' , 'b' , 'a' ],
240
+ 'data' : [1.0 , 2.0 , 3.0 , 4.0 , 5.0 ]},
241
+ columns = ['key' , 'data' ])
242
+ expected = pd .concat ([df .iloc [1 :], df .iloc [1 :]],
243
+ axis = 1 , keys = ['float64' , 'object' ])
244
+ result = df .groupby ([str (x ) for x in df .dtypes ],
245
+ axis = 1 ).apply (lambda x : df .iloc [1 :])
246
+
247
+ assert_frame_equal (result , expected )
248
+
249
+ @pytest .mark .xfail (reason = ("GH 20066; function passed into apply "
250
+ "returns a DataFrame with the same index "
251
+ "as the one to create GroupBy object." ))
252
+ def test_apply_trivial_fail (self ):
253
+ # GH 20066
254
+ # trivial apply fails if the constant dataframe has the same index
255
+ # with the one used to create GroupBy object.
256
+ df = pd .DataFrame ({'key' : ['a' , 'a' , 'b' , 'b' , 'a' ],
257
+ 'data' : [1.0 , 2.0 , 3.0 , 4.0 , 5.0 ]},
258
+ columns = ['key' , 'data' ])
259
+ expected = pd .concat ([df , df ],
260
+ axis = 1 , keys = ['float64' , 'object' ])
261
+ result = df .groupby ([str (x ) for x in df .dtypes ],
262
+ axis = 1 ).apply (lambda x : df )
263
+
264
+ assert_frame_equal (result , expected )
265
+
236
266
def test_time_field_bug (self ):
237
267
# Test a fix for the following error related to GH issue 11324 When
238
268
# non-key fields in a group-by dataframe contained time-based fields
0 commit comments