Skip to content

ENH add date to DatetimeIndex #3614

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

Merged
merged 1 commit into from
May 17, 2013
Merged
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
3 changes: 2 additions & 1 deletion RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pandas 0.11.1
- support datelike columns with a timezone as data_columns (GH2852_)
- table writing performance improvements.
- Add modulo operator to Series, DataFrame
- Add ``date`` method to DatetimeIndex

**API Changes**

Expand Down Expand Up @@ -275,7 +276,7 @@ pandas 0.11.0
on rhs (GH3216_)
- Treat boolean values as integers (values 1 and 0) for numeric
operations. (GH2641_)
- Add ``time()`` method to DatetimeIndex (GH3180_)
- Add ``time`` method to DatetimeIndex (GH3180_)
- Return NA when using Series.str[...] for values that are not long enough
(GH3223_)
- Display cursor coordinate information in time-series plots (GH1670_)
Expand Down
11 changes: 9 additions & 2 deletions pandas/tseries/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -1319,11 +1319,18 @@ def freqstr(self):
@property
def time(self):
"""
Returns array of datetime.time. The time of the day
Returns numpy array of datetime.time. The time part of the Timestamps.
"""
# can't call self.map() which tries to treat func as ufunc
# and causes recursion warnings on python 2.6
return _algos.arrmap_object(self.asobject, lambda x:x.time())
return _algos.arrmap_object(self.asobject, lambda x: x.time())

@property
def date(self):
"""
Returns numpy array of datetime.date. The date part of the Timestamps.
"""
return _algos.arrmap_object(self.asobject, lambda x: x.date())


def normalize(self):
Expand Down
6 changes: 6 additions & 0 deletions pandas/tseries/tests/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -1847,6 +1847,12 @@ def test_time(self):
expected = [t.time() for t in rng]
self.assert_((result == expected).all())

def test_date(self):
rng = pd.date_range('1/1/2000', freq='12H', periods=10)
result = pd.Index(rng).date
expected = [t.date() for t in rng]
self.assert_((result == expected).all())


class TestLegacySupport(unittest.TestCase):
_multiprocess_can_split_ = True
Expand Down