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 - attribute removed from Pandas v1.0.0 #8610

Closed
5 tasks done
nameloCmaS opened this issue Jan 15, 2024 · 2 comments · Fixed by #8664
Closed
5 tasks done

dt.weekday_name - attribute removed from Pandas v1.0.0 #8610

nameloCmaS opened this issue Jan 15, 2024 · 2 comments · Fixed by #8664
Labels
bug needs triage Issue that has not been reviewed by xarray team member

Comments

@nameloCmaS
Copy link
Contributor

nameloCmaS commented Jan 15, 2024

What happened?

Calling the weekday_name such as:
da.dt.weekday_name
raises an exception.

Looking into it more deeply, i.e. xarray source it can be seen the values are converted to a Pandas Series and the attribute called directly from that series.

This attribute was removed from Pandas in v1.0.0

Removed Timestamp.weekday_name, DatetimeIndex.weekday_name, and Series.dt.weekday_name (GH 18164)

It was replaced with the method day_name() - so the code would need to consider this case separately.

What did you expect to happen?

Return the weekday_name.

Minimal Complete Verifiable Example

import pandas as pd
import xarray as xr
da = xr.DataArray(pd.date_range("2024-01-15", periods=2))
day_name = da.dt.weekday_name

MVCE confirmation

  • Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
  • Complete example — the example is self-contained, including all data and the text of any traceback.
  • Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
  • New issue — a search of GitHub Issues suggests this is not a duplicate.
  • Recent environment — the issue occurs with the latest version of xarray and its dependencies.

Relevant log output

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/sam/Documents/GitHub/filebasedbim/venv/lib/python3.12/site-packages/xarray/core/accessor_dt.py", line 462, in weekday_name
    return self._date_field("weekday_name", object)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/sam/Documents/GitHub/filebasedbim/venv/lib/python3.12/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/Documents/GitHub/filebasedbim/venv/lib/python3.12/site-packages/xarray/core/accessor_dt.py", line 139, in _get_date_field
    out = access_method(values, name)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/sam/Documents/GitHub/filebasedbim/venv/lib/python3.12/site-packages/xarray/core/accessor_dt.py", line 97, in _access_through_series
    field_values = getattr(values_as_series.dt, name).values
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'DatetimeProperties' object has no attribute 'weekday_name'

Anything else we need to know?

day_name() accepts a locale, and if not provided, defaults to 'en_US.utf8'.
Pandas also have the month_name() method which may be worth implementing at the same time.

Alternatively, if locale implementation is not desired, weekday_name should be depreciated and removed as Pandas > v1.5 is required.

Environment

INSTALLED VERSIONS

commit: None
python: 3.12.0 (main, Oct 5 2023, 15:52:37) [Clang 14.0.3 (clang-1403.0.22.14.1)]
python-bits: 64
OS: Darwin
OS-release: 22.6.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: None
LOCALE: (None, 'UTF-8')
libhdf5: None
libnetcdf: None

xarray: 2023.12.0
pandas: 2.1.4
numpy: 1.26.2
scipy: None
netCDF4: None
pydap: None
h5netcdf: None
h5py: None
Nio: None
zarr: None
cftime: None
nc_time_axis: None
iris: None
bottleneck: None
dask: None
distributed: None
matplotlib: None
cartopy: None
seaborn: None
numbagg: None
fsspec: None
cupy: None
pint: None
sparse: None
flox: None
numpy_groupies: None
setuptools: 68.2.2
pip: 23.3.1
conda: None
pytest: 7.4.3
mypy: None
IPython: None
sphinx: None

@nameloCmaS nameloCmaS added bug needs triage Issue that has not been reviewed by xarray team member labels Jan 15, 2024
Copy link

welcome bot commented Jan 15, 2024

Thanks for opening your first issue here at xarray! Be sure to follow the issue template!
If you have an idea for a solution, we would really welcome a Pull Request with proposed changes.
See the Contributing Guide for more.
It may take us a while to respond here, but we really value your contribution. Contributors like you help make xarray better.
Thank you!

@max-sixty
Copy link
Collaborator

Thanks @nameloCmaS . We'd definitely take a PR for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug needs triage Issue that has not been reviewed by xarray team member
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants