Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Series.dt.is_quarter_start and Series.dt.is_quarter_end #9046

Merged
merged 16 commits into from
Aug 17, 2021
34 changes: 27 additions & 7 deletions python/cudf/cudf/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -6086,12 +6086,12 @@ def is_month_end(self):
def is_quarter_start(self):
"""
Boolean indicator if the date is the first day of a quarter.

Returns
-------
Series
Booleans indicating if dates are the begining of a quarter

Example
-------
>>> import pandas as pd, cudf
Expand All @@ -6118,18 +6118,28 @@ def is_quarter_start(self):
7 False
dtype: bool
"""
return ((self.day == 1) & self.month.isin([1, 4, 7, 10])).fillna(False)
day = self.series._column.get_dt_field("day")
first_month = self.series._column.get_dt_field("month").isin(
[1, 4, 7, 10]
)

result = ((day == cudf.Scalar(1)) & first_month).fillna(False)
return Series._from_data(
ColumnAccessor({None: result}),
index=self.series._index,
name=self.series.name,
)

@property
def is_quarter_end(self):
"""
Boolean indicator if the date is the last day of a quarter.

Returns
-------
Series
Booleans indicating if dates are the end of a quarter

Example
-------
>>> import pandas as pd, cudf
Expand All @@ -6156,8 +6166,18 @@ def is_quarter_end(self):
7 False
dtype: bool
"""
return (self.is_month_end & self.month.isin([3, 6, 9, 12])).fillna(
False
day = self.series._column.get_dt_field("day")
last_day = libcudf.datetime.last_day_of_month(self.series._column)
last_day = last_day.get_dt_field("day")
last_month = self.series._column.get_dt_field("month").isin(
[3, 6, 9, 12]
)

result = ((day == last_day) & last_month).fillna(False)
return Series._from_data(
ColumnAccessor({None: result}),
TravisHester marked this conversation as resolved.
Show resolved Hide resolved
index=self.series._index,
name=self.series.name,
)

@property
Expand Down