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

dt.weekday_name - removal of function #8664

Merged
merged 12 commits into from
Jan 25, 2024
Merged

Conversation

nameloCmaS
Copy link
Contributor

Expanding on #8610, I considered the below in deciding to remove the parameter dt.weekday_name:

  1. The parameter has not been able to be used since v0.17.0 (bump the dependencies #4942) which is when pandas v1.0.0 was set as the minimum required version. This is 3 years it has not worked.
  2. No one has raised an issue re this in 3 years, so assume it is not used or required by the user base; thus it is unlikely to break any code.
  3. It was not in the test suite.
  4. There are more flexible ways to get date strings such as strftime() which account for localisation.

I considered a number of solutions with the above:

  1. Add a warning and return an empty T_DataArray.
  2. Return the weekday_name using strftime() or similar.
  3. Remove the parameter and implement the pandas day_name method (but this isn't in cftime).

It should also be noted that the parameter does not work for both pandas.dt and cftime:

import xarray as xr
import dumpy as np
dates = xr.cftime_range(start="0001", periods=2, freq="MS", calendar="noleap")
da = xr.DataArray(dates)
da.dt.weekday_name

returns:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/sam/miniconda3/envs/xarray-docs/lib/python3.10/site-packages/xarray/core/accessor_dt.py", line 462, in weekday_name
    return self._date_field("weekday_name", object)
  File "/Users/sam/miniconda3/envs/xarray-docs/lib/python3.10/site-packages/xarray/core/accessor_dt.py", line 245, in _date_field
    result = _get_date_field(_index_or_data(self._obj), name, dtype)
  File "/Users/sam/miniconda3/envs/xarray-docs/lib/python3.10/site-packages/xarray/core/accessor_dt.py", line 139, in _get_date_field
    out = access_method(values, name)
  File "/Users/sam/miniconda3/envs/xarray-docs/lib/python3.10/site-packages/xarray/core/accessor_dt.py", line 65, in _access_through_cftimeindex
    field_values = getattr(values_as_cftimeindex, name)
AttributeError: 'CFTimeIndex' object has no attribute 'weekday_name'

Copy link
Collaborator

@max-sixty max-sixty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is 3 years it has not worked.

OK, that's fairly persuasive!


Thanks @nameloCmaS !

xarray/core/accessor_dt.py Outdated Show resolved Hide resolved
xarray/core/accessor_dt.py Outdated Show resolved Hide resolved
doc/whats-new.rst Outdated Show resolved Hide resolved
nameloCmaS and others added 3 commits January 25, 2024 07:10
Co-authored-by: Maximilian Roos <5635139+max-sixty@users.noreply.github.com>
Co-authored-by: Maximilian Roos <5635139+max-sixty@users.noreply.github.com>
Co-authored-by: Maximilian Roos <5635139+max-sixty@users.noreply.github.com>
@max-sixty max-sixty merged commit db9e448 into pydata:main Jan 25, 2024
28 of 29 checks passed
andersy005 added a commit to TomNicholas/xarray that referenced this pull request Jan 30, 2024
* main: (153 commits)
  Add overloads to get_axis_num (pydata#8547)
  Fix CI: temporary pin pytest version to 7.4.* (pydata#8682)
  Bump the actions group with 1 update (pydata#8678)
  [namedarray] split `.set_dims()` into `.expand_dims()` and `broadcast_to()` (pydata#8380)
  Add chunk-friendly code path to `encode_cf_datetime` and `encode_cf_timedelta` (pydata#8575)
  Fix NetCDF4 C version detection (pydata#8675)
  groupby: Don't set `method` by default on flox>=0.9 (pydata#8657)
  Fix automatic broadcasting when wrapping array api class (pydata#8669)
  Fix unstack method when wrapping array api class (pydata#8668)
  Fix `variables` arg typo in `Dataset.sortby()` docstring (pydata#8670)
  dt.weekday_name - removal of function (pydata#8664)
  Add `dev` dependencies to `pyproject.toml` (pydata#8661)
  CI: Pin scientific-python/upload-nightly-action to release sha (pydata#8662)
  Update HOW_TO_RELEASE.md by clarifying where RTD build can be found (pydata#8655)
  ruff: use extend-exclude (pydata#8649)
  new whats-new section (pydata#8652)
  xfail another test on windows (pydata#8648)
  use first element of residual in _nonpolyfit_1d (pydata#8647)
  whatsnew for v2024.01.1
  implement `isnull` using `full_like` instead of `zeros_like` (pydata#7395)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dt.weekday_name - attribute removed from Pandas v1.0.0
2 participants