Skip to content
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
48 changes: 47 additions & 1 deletion databricks/koalas/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.
#
from functools import partial
from typing import Any
from typing import Any, Optional

import pandas as pd
from pandas.api.types import is_hashable
Expand Down Expand Up @@ -523,6 +523,52 @@ def round(self, freq, *args, **kwargs) -> "DatetimeIndex":

return DatetimeIndex(self.to_series().dt.round(freq, *args, **kwargs))

def month_name(self, locale: Optional[str] = None) -> Index:
"""
Return the month names of the DatetimeIndex with specified locale.

Parameters
----------
locale : str, optional
Locale determining the language in which to return the month name.
Default is English locale.

Returns
-------
Index
Series of month names.

Examples
--------
>>> idx = ks.date_range(start='2018-01', freq='M', periods=3)
>>> idx.month_name()
Index(['January', 'February', 'March'], dtype='object')
"""
return Index(self.to_series().dt.month_name(locale))

def day_name(self, locale: Optional[str] = None) -> Index:
"""
Return the day names of the series with specified locale.

Parameters
----------
locale : str, optional
Locale determining the language in which to return the day name.
Default is English locale.

Returns
-------
Index
Index of day names.

Examples
--------
>>> idx = ks.date_range(start='2018-01-01', freq='D', periods=3)
>>> idx.day_name()
Index(['Monday', 'Tuesday', 'Wednesday'], dtype='object')
"""
return Index(self.to_series().dt.day_name(locale))

def normalize(self) -> "DatetimeIndex":
"""
Convert times to midnight.
Expand Down
2 changes: 0 additions & 2 deletions databricks/koalas/missing/indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@ class MissingPandasLikeDatetimeIndex(MissingPandasLikeIndex):
to_period = _unsupported_function("to_period", cls="DatetimeIndex")
to_perioddelta = _unsupported_function("to_perioddelta", cls="DatetimeIndex")
to_pydatetime = _unsupported_function("to_pydatetime", cls="DatetimeIndex")
month_name = _unsupported_function("month_name", cls="DatetimeIndex")
day_name = _unsupported_function("day_name", cls="DatetimeIndex")
mean = _unsupported_function("mean", cls="DatetimeIndex")
std = _unsupported_function("std", cls="DatetimeIndex")

Expand Down
8 changes: 8 additions & 0 deletions databricks/koalas/tests/indexes/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ def test_round(self):

self._disallow_nanoseconds(self.kidxs[0].round)

def test_day_name(self):
for kidx, pidx in self.idx_pairs:
self.assert_eq(kidx.day_name(), pidx.day_name())

def test_month_name(self):
for kidx, pidx in self.idx_pairs:
self.assert_eq(kidx.day_name(), pidx.day_name())

def test_normalize(self):
for kidx, pidx in self.idx_pairs:
self.assert_eq(kidx.normalize(), pidx.normalize())
Expand Down
4 changes: 3 additions & 1 deletion docs/source/reference/indexing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -333,4 +333,6 @@ Time-specific operations
DatetimeIndex.strftime
DatetimeIndex.round
DatetimeIndex.floor
DatetimeIndex.ceil
DatetimeIndex.ceil
DatetimeIndex.month_name
DatetimeIndex.day_name