Skip to content

Commit 26ed691

Browse files
committed
Fix whatsnew and add tests
1 parent f46ce84 commit 26ed691

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
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

+25-10
Original file line numberDiff line numberDiff line change
@@ -221,29 +221,37 @@ 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')},
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]},
226232
{'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')}),
233+
tz='US/Central'),
234+
'foo': [1]}),
230235
({'id': ['A', 'B', 'A'],
231236
'time': [Timestamp('2012-01-01 13:00:00',
232237
tz='America/New_York'),
233238
Timestamp('2012-02-01 14:00:00',
234239
tz='US/Central'),
235240
Timestamp('2012-03-01 12:00:00',
236-
tz='Europe/London')]},
241+
tz='Europe/London')],
242+
'foo': [1, 2, 3]},
237243
{'id': ['A', 'B'],
238244
'time': [Timestamp('2012-01-01 13:00:00',
239245
tz='America/New_York'),
240246
Timestamp('2012-02-01 14:00:00',
241-
tz='US/Central')]},
247+
tz='US/Central')],
248+
'foo': [1, 2]},
242249
{'id': ['A', 'B'],
243250
'time': [Timestamp('2012-03-01 12:00:00',
244251
tz='Europe/London'),
245252
Timestamp('2012-02-01 14:00:00',
246-
tz='US/Central')]})
253+
tz='US/Central')],
254+
'foo': [3, 2]})
247255
])
248256
def test_first_last_tz(data, expected_first, expected_last):
249257
# GH15884
@@ -254,12 +262,19 @@ def test_first_last_tz(data, expected_first, expected_last):
254262

255263
result = df.groupby('id', as_index=False).first()
256264
expected = DataFrame(expected_first)
257-
assert_frame_equal(result, expected)
265+
cols = ['id', 'time', 'foo']
266+
assert_frame_equal(result[cols], expected[cols])
267+
268+
result = df.groupby('id', as_index=False)['time'].first()
269+
assert_frame_equal(result, expected[['id', 'time']])
258270

259271
result = df.groupby('id', as_index=False).last()
260272
expected = DataFrame(expected_last)
261-
assert_frame_equal(result, expected)
273+
cols = ['id', 'time', 'foo']
274+
assert_frame_equal(result[cols], expected[cols])
262275

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

264279
def test_nth_multi_index_as_expected():
265280
# PR 9090, related to issue 8979

0 commit comments

Comments
 (0)