Skip to content

BUG: Series.ffill() with mixed dtypes containing tz-aware datetimes f… #14960

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.20.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,4 @@ Bug Fixes
- Bug in ``Series.unique()`` in which unsigned 64-bit integers were causing overflow (:issue:`14721`)
- Require at least 0.23 version of cython to avoid problems with character encodings (:issue:`14699`)
- Bug in converting object elements of array-like objects to unsigned 64-bit integers (:issue:`4471`)
- Bug in Series.ffill() with mixed dtypes containing tz-aware datetimes. (:issue:`14956`)
2 changes: 1 addition & 1 deletion pandas/src/inference.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ def maybe_convert_objects(ndarray[object] objects, bint try_float=0,

# we try to coerce datetime w/tz but must all have the same tz
if seen_datetimetz:
if len(set([ getattr(val, 'tz', None) for val in objects ])) == 1:
if len(set([getattr(val, 'tzinfo', None) for val in objects])) == 1:
from pandas import DatetimeIndex
return DatetimeIndex(objects)
seen_object = 1
Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/series/test_missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,12 @@ def test_ffill(self):
ts[2] = np.NaN
assert_series_equal(ts.ffill(), ts.fillna(method='ffill'))

def test_ffill_mixed_dtypes_without_missing_data(self):
# GH14956
series = pd.Series([datetime(2015, 1, 1, tzinfo=pytz.utc), 1])
result = series.ffill()
assert_series_equal(series, result)

def test_bfill(self):
ts = Series([0., 1., 2., 3., 4.], index=tm.makeDateIndex(5))
ts[2] = np.NaN
Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/types/test_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import re
from datetime import datetime, date, timedelta, time
import numpy as np
import pytz

import pandas as pd
from pandas import lib, tslib
Expand Down Expand Up @@ -275,6 +276,14 @@ def test_maybe_convert_objects_uint64(self):
exp = np.array([2**63, -1], dtype=object)
tm.assert_numpy_array_equal(lib.maybe_convert_objects(arr), exp)

def test_mixed_dtypes_remain_object_array(self):
# GH14956
array = np.array([datetime(2015, 1, 1, tzinfo=pytz.utc), 1],
dtype=object)
result = lib.maybe_convert_objects(array)
tm.assert_numpy_array_equal(result, array)
self.assertTrue(result.dtype == object)


class TestTypeInference(tm.TestCase):
_multiprocess_can_split_ = True
Expand Down