Skip to content
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
7 changes: 7 additions & 0 deletions pandas/tseries/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -1266,6 +1266,13 @@ def freqstr(self):
dayofyear = _field_accessor('dayofyear', 'doy')
quarter = _field_accessor('quarter', 'q')

@property
def time(self):
"""
Returns array of datetime.time. The time of the day
"""
return self.map(lambda t: t.time())

def normalize(self):
"""
Return DatetimeIndex with times to midnight. Length is unaltered
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 @@ -1778,6 +1778,12 @@ def test_union_with_DatetimeIndex(self):
i1.union(i2) # Works
i2.union(i1) # Fails with "AttributeError: can't set attribute"

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


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