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
3 changes: 3 additions & 0 deletions bigframes/operations/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ def unit(self) -> str:
# Assumption: pyarrow dtype
return self._data._dtype.pyarrow_dtype.unit

def day_name(self) -> series.Series:
return self.strftime("%A")

def strftime(self, date_format: str) -> series.Series:
return self._data._apply_unary_op(ops.StrftimeOp(date_format=date_format))

Expand Down
15 changes: 15 additions & 0 deletions tests/system/small/operations/test_datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,21 @@ def test_dt_dayofyear(scalars_dfs, col_name):
assert_series_equal(pd_result, bf_result, check_dtype=False)


@pytest.mark.parametrize(
("col_name",),
DATE_COLUMNS,
)
def test_dt_day_name(scalars_dfs, col_name):
pytest.importorskip("pandas", minversion="2.0.0")
scalars_df, scalars_pandas_df = scalars_dfs
bf_series: bigframes.series.Series = scalars_df[col_name]

bf_result = bf_series.dt.day_name().to_pandas()
pd_result = scalars_pandas_df[col_name].dt.day_name()

assert_series_equal(pd_result, bf_result, check_dtype=False)


@pytest.mark.parametrize(
("col_name",),
DATE_COLUMNS,
Expand Down
24 changes: 24 additions & 0 deletions third_party/bigframes_vendored/pandas/core/indexes/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,30 @@ def day_of_week(self):

raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)

@property
def day_name(self):
"""
Return the day names in english.
**Examples:**
>>> s = bpd.Series(pd.date_range(start="2018-01-01", freq="D", periods=3))
>>> s
0 2018-01-01 00:00:00
1 2018-01-02 00:00:00
2 2018-01-03 00:00:00
dtype: timestamp[us][pyarrow]
>>> s.dt.day_name()
0 Monday
1 Tuesday
2 Wednesday
dtype: string
Returns:
Series: Series of day names.
"""
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)

@property
def dayofyear(self):
"""The ordinal day of the year.
Expand Down