Skip to content

Commit 7bb7a3b

Browse files
committed
Fix whatsnew and add tests
1 parent f46ce84 commit 7bb7a3b

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

doc/source/whatsnew/v0.24.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ Plotting
225225
Groupby/Resample/Rolling
226226
^^^^^^^^^^^^^^^^^^^^^^^^
227227

228-
- Bug in :func:`pandas.core.groupby.first` and :func:`pandas.core.groupby.last` with ``as_index=False`` leading to the loss of timezone information (:issue:`15884`)
228+
- Bug in :func:`pandas.core.groupby.GroupBy.first` and :func:`pandas.core.groupby.GroupBy.last` with ``as_index=False`` leading to the loss of timezone information (:issue:`15884`)
229229
-
230230
-
231231

pandas/tests/groupby/test_nth.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -233,17 +233,20 @@ def test_nth_multi_index(three_group):
233233
Timestamp('2012-02-01 14:00:00',
234234
tz='US/Central'),
235235
Timestamp('2012-03-01 12:00:00',
236-
tz='Europe/London')]},
236+
tz='Europe/London')],
237+
'foo': [1, 2, 3]},
237238
{'id': ['A', 'B'],
238239
'time': [Timestamp('2012-01-01 13:00:00',
239240
tz='America/New_York'),
240241
Timestamp('2012-02-01 14:00:00',
241-
tz='US/Central')]},
242+
tz='US/Central')],
243+
'foo': [1, 2]},
242244
{'id': ['A', 'B'],
243245
'time': [Timestamp('2012-03-01 12:00:00',
244246
tz='Europe/London'),
245247
Timestamp('2012-02-01 14:00:00',
246-
tz='US/Central')]})
248+
tz='US/Central')],
249+
'foo': [3, 2]})
247250
])
248251
def test_first_last_tz(data, expected_first, expected_last):
249252
# GH15884
@@ -256,10 +259,15 @@ def test_first_last_tz(data, expected_first, expected_last):
256259
expected = DataFrame(expected_first)
257260
assert_frame_equal(result, expected)
258261

262+
result = df.groupby('id', as_index=False)['time'].first()
263+
assert_frame_equal(result, expected[['id', 'time']])
264+
259265
result = df.groupby('id', as_index=False).last()
260266
expected = DataFrame(expected_last)
261267
assert_frame_equal(result, expected)
262268

269+
result = df.groupby('id', as_index=False)['time'].last()
270+
assert_frame_equal(result, expected[['id', 'time']])
263271

264272
def test_nth_multi_index_as_expected():
265273
# PR 9090, related to issue 8979

0 commit comments

Comments
 (0)