Skip to content

Commit 97b4295

Browse files
Adrianjreback
Adrian
authored andcommitted
BUG: Series.ffill() with mixed dtypes containing tz-aware datetimes fails.
closes pandas-dev#14956 closes pandas-dev#14960
1 parent 8f7ba1b commit 97b4295

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

doc/source/whatsnew/v0.20.0.txt

+15
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ Bug Fixes
287287

288288

289289
- Bug in ``pd.read_msgpack()`` in which ``Series`` categoricals were being improperly processed (:issue:`14901`)
290+
- Bug in ``Series.ffill()`` with mixed dtypes containing tz-aware datetimes. (:issue:`14956`)
290291

291292

292293

@@ -299,6 +300,20 @@ Bug Fixes
299300

300301
- Bug in ``Series.unique()`` in which unsigned 64-bit integers were causing overflow (:issue:`14721`)
301302
- Bug in ``pd.unique()`` in which unsigned 64-bit integers were causing overflow (:issue:`14915`)
303+
304+
305+
306+
307+
308+
309+
310+
311+
312+
313+
314+
315+
316+
302317
- Require at least 0.23 version of cython to avoid problems with character encodings (:issue:`14699`)
303318
- Bug in converting object elements of array-like objects to unsigned 64-bit integers (:issue:`4471`)
304319
- Bug in ``pd.pivot_table()`` where no error was raised when values argument was not in the columns (:issue:`14938`)

pandas/src/inference.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ def maybe_convert_objects(ndarray[object] objects, bint try_float=0,
859859

860860
# we try to coerce datetime w/tz but must all have the same tz
861861
if seen_datetimetz:
862-
if len(set([ getattr(val, 'tz', None) for val in objects ])) == 1:
862+
if len(set([getattr(val, 'tzinfo', None) for val in objects])) == 1:
863863
from pandas import DatetimeIndex
864864
return DatetimeIndex(objects)
865865
seen_object = 1

pandas/tests/series/test_missing.py

+6
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,12 @@ def test_ffill(self):
386386
ts[2] = np.NaN
387387
assert_series_equal(ts.ffill(), ts.fillna(method='ffill'))
388388

389+
def test_ffill_mixed_dtypes_without_missing_data(self):
390+
# GH14956
391+
series = pd.Series([datetime(2015, 1, 1, tzinfo=pytz.utc), 1])
392+
result = series.ffill()
393+
assert_series_equal(series, result)
394+
389395
def test_bfill(self):
390396
ts = Series([0., 1., 2., 3., 4.], index=tm.makeDateIndex(5))
391397
ts[2] = np.NaN

pandas/tests/types/test_inference.py

+8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import re
1212
from datetime import datetime, date, timedelta, time
1313
import numpy as np
14+
import pytz
1415

1516
import pandas as pd
1617
from pandas import lib, tslib
@@ -275,6 +276,13 @@ def test_maybe_convert_objects_uint64(self):
275276
exp = np.array([2**63, -1], dtype=object)
276277
tm.assert_numpy_array_equal(lib.maybe_convert_objects(arr), exp)
277278

279+
def test_mixed_dtypes_remain_object_array(self):
280+
# GH14956
281+
array = np.array([datetime(2015, 1, 1, tzinfo=pytz.utc), 1],
282+
dtype=object)
283+
result = lib.maybe_convert_objects(array, convert_datetime=1)
284+
tm.assert_numpy_array_equal(result, array)
285+
278286

279287
class TestTypeInference(tm.TestCase):
280288
_multiprocess_can_split_ = True

0 commit comments

Comments
 (0)