diff --git a/bigframes/operations/datetimes.py b/bigframes/operations/datetimes.py index 608089ab41..3f2d16a896 100644 --- a/bigframes/operations/datetimes.py +++ b/bigframes/operations/datetimes.py @@ -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)) diff --git a/tests/system/small/operations/test_datetimes.py b/tests/system/small/operations/test_datetimes.py index 1462a68b49..d6a90597b4 100644 --- a/tests/system/small/operations/test_datetimes.py +++ b/tests/system/small/operations/test_datetimes.py @@ -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, diff --git a/third_party/bigframes_vendored/pandas/core/indexes/accessor.py b/third_party/bigframes_vendored/pandas/core/indexes/accessor.py index b9eb363b29..ee4de44b80 100644 --- a/third_party/bigframes_vendored/pandas/core/indexes/accessor.py +++ b/third_party/bigframes_vendored/pandas/core/indexes/accessor.py @@ -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.