@@ -2085,8 +2085,8 @@ def test_groupby_head_tail(self):
2085
2085
assert_frame_equal (df .loc [[0 , 2 ]], g_not_as .head (1 ))
2086
2086
assert_frame_equal (df .loc [[1 , 2 ]], g_not_as .tail (1 ))
2087
2087
2088
- empty_not_as = DataFrame (columns = df .columns , index = pd . Index (
2089
- [], dtype = df .index .dtype ))
2088
+ empty_not_as = DataFrame (columns = df .columns ,
2089
+ index = pd . Index ( [], dtype = df .index .dtype ))
2090
2090
empty_not_as ['A' ] = empty_not_as ['A' ].astype (df .A .dtype )
2091
2091
empty_not_as ['B' ] = empty_not_as ['B' ].astype (df .B .dtype )
2092
2092
assert_frame_equal (empty_not_as , g_not_as .head (0 ))
@@ -4549,6 +4549,15 @@ def test_groupby_with_empty(self):
4549
4549
grouped = series .groupby (grouper )
4550
4550
assert next (iter (grouped ), None ) is None
4551
4551
4552
+ def test_groupby_with_single_column (self ):
4553
+ df = pd .DataFrame ({'a' : list ('abssbab' )})
4554
+ tm .assert_frame_equal (df .groupby ('a' ).get_group ('a' ), df .iloc [[0 , 5 ]])
4555
+ # GH 13530
4556
+ exp = pd .DataFrame ([], index = pd .Index (['a' , 'b' , 's' ], name = 'a' ))
4557
+ tm .assert_frame_equal (df .groupby ('a' ).count (), exp )
4558
+ tm .assert_frame_equal (df .groupby ('a' ).sum (), exp )
4559
+ tm .assert_frame_equal (df .groupby ('a' ).nth (1 ), exp )
4560
+
4552
4561
def test_groupby_with_small_elem (self ):
4553
4562
# GH 8542
4554
4563
# length=2
@@ -4989,8 +4998,8 @@ def test_cumcount_empty(self):
4989
4998
ge = DataFrame ().groupby (level = 0 )
4990
4999
se = Series ().groupby (level = 0 )
4991
5000
4992
- e = Series ( dtype = 'int64'
4993
- ) # edge case, as this is usually considered float
5001
+ # edge case, as this is usually considered float
5002
+ e = Series ( dtype = 'int64' )
4994
5003
4995
5004
assert_series_equal (e , ge .cumcount ())
4996
5005
assert_series_equal (e , se .cumcount ())
0 commit comments