Skip to content

Commit

Permalink
Series datetime is_month_start (#8844)
Browse files Browse the repository at this point in the history
Addressing feature request #8678. `is_month_start` returns a series indicating whether each date is the first day of the month.

Authors:
  - Sarah Yurick (https://github.com/sarahyurick)

Approvers:
  - Ram (Ramakrishna Prabhu) (https://github.com/rgsl888prabhu)
  - https://github.com/brandon-b-miller

URL: #8844
  • Loading branch information
sarahyurick authored Jul 28, 2021
1 parent 904222b commit 0078bf6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
12 changes: 12 additions & 0 deletions python/cudf/cudf/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -6446,6 +6446,18 @@ def is_leap_year(self):
name=self.series.name,
)

@property
def is_month_start(self):
"""
Boolean indicator if the date is the first day of the month.
Returns
-------
Series
Booleans indicating if dates are the first day of the month.
"""
return (self.day == 1).fillna(False)

def _get_dt_field(self, field):
out_column = self.series._column.get_dt_field(field)
return Series(
Expand Down
29 changes: 29 additions & 0 deletions python/cudf/cudf/tests/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -1297,3 +1297,32 @@ def test_is_leap_year():
got2 = gIndex.is_leap_year

assert_eq(expect2, got2)


@pytest.mark.parametrize(
"data",
[
[
"2020-05-31",
None,
"1999-12-01",
"2000-12-21",
None,
"1900-02-28",
"1800-03-14",
"2100-03-10",
"1970-01-01",
"1969-12-11",
]
],
)
@pytest.mark.parametrize("dtype", ["datetime64[ns]"])
def test_is_month_start(data, dtype):
# Series
ps = pd.Series(data, dtype=dtype)
gs = cudf.from_pandas(ps)

expect = ps.dt.is_month_start
got = gs.dt.is_month_start

assert_eq(expect, got)

0 comments on commit 0078bf6

Please sign in to comment.