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

Add date attribute to datetime accessor #4994

Merged
merged 10 commits into from
Mar 16, 2021
8 changes: 8 additions & 0 deletions xarray/core/accessor_dt.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def _access_through_cftimeindex(values, name):
if name == "season":
months = values_as_cftimeindex.month
field_values = _season_from_months(months)
elif name == "date":
raise AttributeError(
"Attribute `date` is not available for CFTimeIndex. Consider using `floor('D')` instead."
andersy005 marked this conversation as resolved.
Show resolved Hide resolved
)
else:
field_values = getattr(values_as_cftimeindex, name)
return field_values.reshape(values.shape)
Expand Down Expand Up @@ -415,6 +419,10 @@ def weekofyear(self):
"time", "Timestamps corresponding to datetimes", object
)

date = Properties._tslib_field_accessor(
"date", "Date corresponding to datetimes", object
)

is_month_start = Properties._tslib_field_accessor(
"is_month_start",
"Indicates whether the date is the first day of the month.",
Expand Down