Skip to content

Commit 4c6b9ba

Browse files
author
Adrian
committed
BUG: Series.ffill() with mixed dtypes containing tz-aware datetimes fails. (GH14956)
1 parent 3e4f839 commit 4c6b9ba

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

doc/source/whatsnew/v0.20.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -300,3 +300,4 @@ Bug Fixes
300300
- Bug in ``Series.unique()`` in which unsigned 64-bit integers were causing overflow (:issue:`14721`)
301301
- Require at least 0.23 version of cython to avoid problems with character encodings (:issue:`14699`)
302302
- Bug in converting object elements of array-like objects to unsigned 64-bit integers (:issue:`4471`)
303+
- Bug in Series.ffill() with mixed dtypes containing tz-aware datetimes. (:issue:`14956`)

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

+9
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,14 @@ 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)
284+
tm.assert_numpy_array_equal(result, array)
285+
self.assertTrue(result.dtype == object)
286+
278287

279288
class TestTypeInference(tm.TestCase):
280289
_multiprocess_can_split_ = True

0 commit comments

Comments
 (0)