id,node_id,number,title,user,state,locked,assignee,milestone,comments,created_at,updated_at,closed_at,author_association,active_lock_reason,draft,pull_request,body,reactions,performed_via_github_app,state_reason,repo,type 2142410162,I_kwDOAMm_X85_spWy,8770,Error in xr.date_range with exactly three parameters provided.,46948104,closed,0,,,2,2024-02-19T13:45:00Z,2024-02-24T12:43:20Z,2024-02-24T12:43:20Z,CONTRIBUTOR,,,,"### What happened? I was trying to create a list of a fixed number of N dates from start to end using the ""periods"" argument of xr.date_range. ### What did you expect to happen? To obtain a DatetimeIndex object with N period's dates between the starting date and the ending date. ### Minimal Complete Verifiable Example ```Python import xarray as xr from datetime import datetime # Attempt to create a date range with exactly three parameters xr.date_range(start=datetime(1961, 1, 1), end=datetime(1991, 1, 1), periods=3) ``` ### MVCE confirmation - [X] Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray. - [x] Complete example — the example is self-contained, including all data and the text of any traceback. - [x] Verifiable example — the example copy & pastes into an IPython prompt or [Binder notebook](https://mybinder.org/v2/gh/pydata/xarray/main?urlpath=lab/tree/doc/examples/blank_template.ipynb), returning the result. - [X] New issue — a search of GitHub Issues suggests this is not a duplicate. - [x] Recent environment — the issue occurs with the latest version of xarray and its dependencies. ### Relevant log output ```Python Traceback (most recent call last): File """", line 1, in File ""/home/roberto/miniconda3/envs/gs1/lib/python3.11/site-packages/xarray/coding/cftime_offsets.py"", line 1225, in date_range return pd.date_range( ^^^^^^^^^^^^^^ File ""/home/roberto/miniconda3/envs/gs1/lib/python3.11/site-packages/pandas/core/indexes/datetimes.py"", line 1009, in date_range dtarr = DatetimeArray._generate_range( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File ""/home/roberto/miniconda3/envs/gs1/lib/python3.11/site-packages/pandas/core/arrays/datetimes.py"", line 400, in _generate_range raise ValueError( ValueError: Of the four parameters: start, end, periods, and freq, exactly three must be specified ``` ### Anything else we need to know? When running: ``` import pandas as pd from datetime import datetime pd.date_range(start=datetime(1961, 1, 1), end=datetime(1991, 1, 1), periods=2) ``` Outputs: `DatetimeIndex(['1961-01-01', '1991-01-01'], dtype='datetime64[ns]', freq=None)` ### Environment
/home/roberto/miniconda3/envs/gs1/lib/python3.11/site-packages/_distutils_hack/__init__.py:33: UserWarning: Setuptools is replacing distutils. warnings.warn(""Setuptools is replacing distutils."") INSTALLED VERSIONS ------------------ commit: None python: 3.11.6 | packaged by conda-forge | (main, Oct 3 2023, 10:40:35) [GCC 12.3.0] python-bits: 64 OS: Linux OS-release: 6.5.0-14-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: ('en_US', 'UTF-8') libhdf5: 1.12.2 libnetcdf: 4.9.1 xarray: 2023.12.0 pandas: 2.1.4 numpy: 1.26.4 scipy: 1.12.0 netCDF4: 1.6.3 pydap: None h5netcdf: 1.3.0 h5py: 3.8.0 Nio: 1.5.5 zarr: None cftime: 1.6.3 nc_time_axis: None iris: None bottleneck: 1.3.5 dask: 2023.12.1 distributed: 2023.12.1 matplotlib: 3.8.2 cartopy: 0.22.0 seaborn: 0.13.0 numbagg: None fsspec: 2023.12.2 cupy: None pint: None sparse: None flox: None numpy_groupies: None setuptools: 68.2.2 pip: 23.3.2 conda: None pytest: None mypy: None IPython: 8.20.0 sphinx: None
","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/8770/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,completed,13221727,issue