From 394e9184c980bba9a4392bef113edf248a836aff Mon Sep 17 00:00:00 2001 From: rockg Date: Wed, 24 Aug 2016 20:21:33 -0400 Subject: [PATCH] TST/DOC: apply date() with timezones --- doc/source/timeseries.rst | 4 ++-- pandas/tests/series/test_datetime_values.py | 14 +++++++++++++- pandas/tseries/index.py | 3 ++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/doc/source/timeseries.rst b/doc/source/timeseries.rst index a35b8d561a5a7..6f44ee0c87945 100644 --- a/doc/source/timeseries.rst +++ b/doc/source/timeseries.rst @@ -544,8 +544,8 @@ There are several time/date properties that one can access from ``Timestamp`` or second,"The seconds of the datetime" microsecond,"The microseconds of the datetime" nanosecond,"The nanoseconds of the datetime" - date,"Returns datetime.date" - time,"Returns datetime.time" + date,"Returns datetime.date (does not contain timezone information)" + time,"Returns datetime.time (does not contain timezone information)" dayofyear,"The ordinal day of year" weekofyear,"The week ordinal of the year" week,"The week ordinal of the year" diff --git a/pandas/tests/series/test_datetime_values.py b/pandas/tests/series/test_datetime_values.py index 6211597b4a91b..8f2ab0ed28839 100644 --- a/pandas/tests/series/test_datetime_values.py +++ b/pandas/tests/series/test_datetime_values.py @@ -1,7 +1,7 @@ # coding=utf-8 # pylint: disable-msg=E1101,W0612 -from datetime import datetime +from datetime import datetime, date import numpy as np import pandas as pd @@ -410,3 +410,15 @@ def test_between(self): result = s[s.between(s[3], s[17], inclusive=False)] expected = s[5:16].dropna() assert_series_equal(result, expected) + + def test_date_tz(self): + # GH11757 + rng = pd.DatetimeIndex(['2014-04-04 23:56', + '2014-07-18 21:24', + '2015-11-22 22:14'], tz="US/Eastern") + s = Series(rng) + expected = Series([date(2014, 4, 4), + date(2014, 7, 18), + date(2015, 11, 22)]) + assert_series_equal(s.dt.date, expected) + assert_series_equal(s.apply(lambda x: x.date()), expected) diff --git a/pandas/tseries/index.py b/pandas/tseries/index.py index 8f50ddc0f9e41..f78574521ffeb 100644 --- a/pandas/tseries/index.py +++ b/pandas/tseries/index.py @@ -1597,7 +1597,8 @@ def time(self): @property def date(self): """ - Returns numpy array of datetime.date. The date part of the Timestamps. + Returns numpy array of python datetime.date objects (namely, the date + part of Timestamps without timezone information). """ return self._maybe_mask_results(_algos.arrmap_object( self.asobject.values, lambda x: x.date()))