Skip to content

Commit 7408aab

Browse files
committed
Fix whatsnew and add tests
1 parent f46ce84 commit 7408aab

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

doc/source/whatsnew/v0.24.0.txt

Lines changed: 1 addition & 1 deletion
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

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -221,29 +221,38 @@ def test_nth_multi_index(three_group):
221221

222222

223223
@pytest.mark.parametrize('data, expected_first, expected_last', [
224-
({'id': ['A'], 'time': Timestamp('2012-02-01 14:00:00',
225-
tz='US/Central')},
226-
{'id': ['A'], 'time': Timestamp('2012-02-01 14:00:00',
227-
tz='US/Central')},
228-
{'id': ['A'], 'time': Timestamp('2012-02-01 14:00:00',
229-
tz='US/Central')}),
224+
({'id': ['A'],
225+
'time': Timestamp('2012-02-01 14:00:00',
226+
tz='US/Central'),
227+
'foo': [1]},
228+
{'id': ['A'],
229+
'time': Timestamp('2012-02-01 14:00:00',
230+
tz='US/Central'),
231+
'foo': [1]},
232+
{'id': ['A'],
233+
'time': Timestamp('2012-02-01 14:00:00',
234+
tz='US/Central'),
235+
'foo': [1]}),
230236
({'id': ['A', 'B', 'A'],
231237
'time': [Timestamp('2012-01-01 13:00:00',
232238
tz='America/New_York'),
233239
Timestamp('2012-02-01 14:00:00',
234240
tz='US/Central'),
235241
Timestamp('2012-03-01 12:00:00',
236-
tz='Europe/London')]},
242+
tz='Europe/London')],
243+
'foo': [1, 2, 3]},
237244
{'id': ['A', 'B'],
238245
'time': [Timestamp('2012-01-01 13:00:00',
239246
tz='America/New_York'),
240247
Timestamp('2012-02-01 14:00:00',
241-
tz='US/Central')]},
248+
tz='US/Central')],
249+
'foo': [1, 2]},
242250
{'id': ['A', 'B'],
243251
'time': [Timestamp('2012-03-01 12:00:00',
244252
tz='Europe/London'),
245253
Timestamp('2012-02-01 14:00:00',
246-
tz='US/Central')]})
254+
tz='US/Central')],
255+
'foo': [3, 2]})
247256
])
248257
def test_first_last_tz(data, expected_first, expected_last):
249258
# GH15884
@@ -254,12 +263,19 @@ def test_first_last_tz(data, expected_first, expected_last):
254263

255264
result = df.groupby('id', as_index=False).first()
256265
expected = DataFrame(expected_first)
257-
assert_frame_equal(result, expected)
266+
cols = ['id', 'time', 'foo']
267+
assert_frame_equal(result[cols], expected[cols])
268+
269+
result = df.groupby('id', as_index=False)['time'].first()
270+
assert_frame_equal(result, expected[['id', 'time']])
258271

259272
result = df.groupby('id', as_index=False).last()
260273
expected = DataFrame(expected_last)
261-
assert_frame_equal(result, expected)
274+
cols = ['id', 'time', 'foo']
275+
assert_frame_equal(result[cols], expected[cols])
262276

277+
result = df.groupby('id', as_index=False)['time'].last()
278+
assert_frame_equal(result, expected[['id', 'time']])
263279

264280
def test_nth_multi_index_as_expected():
265281
# PR 9090, related to issue 8979

0 commit comments

Comments
 (0)