Skip to content

PR for Pandas issue #14872 / fillna() TZ datetime64 rounded #14905

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 10 commits into from
13 changes: 6 additions & 7 deletions pandas/core/missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
from pandas.compat import range, string_types
from pandas.types.common import (is_numeric_v_string_like,
is_float_dtype, is_datetime64_dtype,
is_integer_dtype, _ensure_float64,
is_scalar,
_DATELIKE_DTYPES,
is_datetime64tz_dtype, is_integer_dtype,
_ensure_float64, is_scalar,
needs_i8_conversion)
from pandas.types.missing import isnull

Expand Down Expand Up @@ -450,7 +449,7 @@ def pad_1d(values, limit=None, mask=None, dtype=None):
_method = None
if is_float_dtype(values):
_method = getattr(algos, 'pad_inplace_%s' % dtype.name, None)
elif dtype in _DATELIKE_DTYPES or is_datetime64_dtype(values):
elif is_datetime64_dtype(dtype) or is_datetime64tz_dtype(dtype):
_method = _pad_1d_datetime
elif is_integer_dtype(values):
values = _ensure_float64(values)
Expand All @@ -475,7 +474,7 @@ def backfill_1d(values, limit=None, mask=None, dtype=None):
_method = None
if is_float_dtype(values):
_method = getattr(algos, 'backfill_inplace_%s' % dtype.name, None)
elif dtype in _DATELIKE_DTYPES or is_datetime64_dtype(values):
elif is_datetime64_dtype(dtype) or is_datetime64tz_dtype(dtype):
_method = _backfill_1d_datetime
elif is_integer_dtype(values):
values = _ensure_float64(values)
Expand All @@ -501,7 +500,7 @@ def pad_2d(values, limit=None, mask=None, dtype=None):
_method = None
if is_float_dtype(values):
_method = getattr(algos, 'pad_2d_inplace_%s' % dtype.name, None)
elif dtype in _DATELIKE_DTYPES or is_datetime64_dtype(values):
elif is_datetime64_dtype(dtype) or is_datetime64tz_dtype(dtype):
_method = _pad_2d_datetime
elif is_integer_dtype(values):
values = _ensure_float64(values)
Expand Down Expand Up @@ -531,7 +530,7 @@ def backfill_2d(values, limit=None, mask=None, dtype=None):
_method = None
if is_float_dtype(values):
_method = getattr(algos, 'backfill_2d_inplace_%s' % dtype.name, None)
elif dtype in _DATELIKE_DTYPES or is_datetime64_dtype(values):
elif is_datetime64_dtype(dtype) or is_datetime64tz_dtype(dtype):
_method = _backfill_2d_datetime
elif is_integer_dtype(values):
values = _ensure_float64(values)
Expand Down
34 changes: 34 additions & 0 deletions pandas/tests/test_dtype_utc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Dec 17 09:34:47 2016

@author: rodolfoxps
"""
import nose
import pandas as pd
import datetime
import pytz
from pandas.util.testing import assert_series_equal


def test_dtype_utc():

data = pd.Series([pd.NaT, pd.NaT,
datetime.datetime(2016, 12, 12, 22, 24, 6, 100001,
tzinfo=pytz.utc)])

filled = data.fillna(method='bfill')

expected = pd.Series([datetime.datetime(2016, 12, 12, 22, 24, 6, 100001,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test needs to go in test_missing (search and out it with other similar tests)

tzinfo=pytz.utc),
datetime.datetime(2016, 12, 12, 22, 24, 6, 100001,
tzinfo=pytz.utc),
datetime.datetime(2016, 12, 12, 22, 24, 6, 100001,
tzinfo=pytz.utc)])

assert_series_equal(filled, expected)

if __name__ == '__main__':
nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],
exit=False)
1 change: 1 addition & 0 deletions pandas/types/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
_NS_DTYPE = np.dtype('M8[ns]')
_TD_DTYPE = np.dtype('m8[ns]')
_INT64_DTYPE = np.dtype(np.int64)

_DATELIKE_DTYPES = set([np.dtype(t)
for t in ['M8[ns]', '<M8[ns]', '>M8[ns]',
'm8[ns]', '<m8[ns]', '>m8[ns]']])
Expand Down