Skip to content

Commit 5e006e4

Browse files
feat: Add Series.dt.day_name (#2218)
1 parent 38abfd8 commit 5e006e4

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

bigframes/operations/datetimes.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ def unit(self) -> str:
148148
# Assumption: pyarrow dtype
149149
return self._data._dtype.pyarrow_dtype.unit
150150

151+
def day_name(self) -> series.Series:
152+
return self.strftime("%A")
153+
151154
def strftime(self, date_format: str) -> series.Series:
152155
return self._data._apply_unary_op(ops.StrftimeOp(date_format=date_format))
153156

tests/system/small/operations/test_datetimes.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,21 @@ def test_dt_dayofyear(scalars_dfs, col_name):
123123
assert_series_equal(pd_result, bf_result, check_dtype=False)
124124

125125

126+
@pytest.mark.parametrize(
127+
("col_name",),
128+
DATE_COLUMNS,
129+
)
130+
def test_dt_day_name(scalars_dfs, col_name):
131+
pytest.importorskip("pandas", minversion="2.0.0")
132+
scalars_df, scalars_pandas_df = scalars_dfs
133+
bf_series: bigframes.series.Series = scalars_df[col_name]
134+
135+
bf_result = bf_series.dt.day_name().to_pandas()
136+
pd_result = scalars_pandas_df[col_name].dt.day_name()
137+
138+
assert_series_equal(pd_result, bf_result, check_dtype=False)
139+
140+
126141
@pytest.mark.parametrize(
127142
("col_name",),
128143
DATE_COLUMNS,

third_party/bigframes_vendored/pandas/core/indexes/accessor.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,30 @@ def day_of_week(self):
9191

9292
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)
9393

94+
@property
95+
def day_name(self):
96+
"""
97+
Return the day names in english.
98+
99+
**Examples:**
100+
>>> s = bpd.Series(pd.date_range(start="2018-01-01", freq="D", periods=3))
101+
>>> s
102+
0 2018-01-01 00:00:00
103+
1 2018-01-02 00:00:00
104+
2 2018-01-03 00:00:00
105+
dtype: timestamp[us][pyarrow]
106+
>>> s.dt.day_name()
107+
0 Monday
108+
1 Tuesday
109+
2 Wednesday
110+
dtype: string
111+
112+
Returns:
113+
Series: Series of day names.
114+
115+
"""
116+
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)
117+
94118
@property
95119
def dayofyear(self):
96120
"""The ordinal day of the year.

0 commit comments

Comments
 (0)