cftime_range missing freq ("W") - Invalid frequency string provided
Open
Nobody has claimed this yet.
enhancement
topic-cftime
- Dominant language
- Python
- Stars
- 4.2k
- Forks
- 1.4k
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 14
Description
Is your feature request related to a problem?
I tend to use xr.cftime_range as a drop in for pandas.date_range. My only reason here is I may able to shave a line and not import pandas.
In doing xr.cftime_range("2020-01-01", periods=1, freq="W") I get
AttributeError Traceback (most recent call last)
/opt/userenvs/ray.bell/main/lib/python3.9/site-packages/xarray/coding/cftime_offsets.py in to_offset(freq)
729 try:
--> 730 freq_data = re.match(_PATTERN, freq).groupdict()
731 except AttributeError:
AttributeError: 'NoneType' object has no attribute 'groupdict'
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
/tmp/ipykernel_549/3579801314.py in <module>
----> 1 xr.cftime_range("2020-01-01", periods=1, freq="W")
/opt/userenvs/ray.bell/main/lib/python3.9/site-packages/xarray/coding/cftime_offsets.py in cftime_range(start, end, periods, freq, normalize, name, closed, calendar)
1041 dates = _generate_linear_range(start, end, periods)
1042 else:
-> 1043 offset = to_offset(freq)
1044 dates = np.array(list(_generate_range(start, end, periods, offset)))
1045
/opt/userenvs/ray.bell/main/lib/python3.9/site-packages/xarray/coding/cftime_offsets.py in to_offset(freq)
730 freq_data = re.match(_PATTERN, freq).groupdict()
731 except AttributeError:
--> 732 raise ValueError("Invalid frequency string provided")
733
734 freq = freq_data["freq"]
ValueError: Invalid frequency string provided
In pandas I get
>>> pd.date_range("2020-01-01", periods=1, freq="W")
DatetimeIndex(['2020-01-05'], dtype='datetime64[ns]', freq='W-SUN')
Describe the solution you'd like
No response
Describe alternatives you've considered
Closing this issue as outside of scope
Additional context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the reported call, then read xarray/coding/cftime_offsets.py around cftime_range and to_offset, where the traceback identifies the failure. Check the existing offset parsing and nearby tests; done means a W frequency is accepted and produces the pandas-compatible weekly result without breaking existing frequencies.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- pandas, python
- Domain
- data
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100