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

ENH/BUG: pd.date_range() still defaults to nanosecond resolution #59031

Open
jorisvandenbossche opened this issue Jun 17, 2024 · 1 comment · May be fixed by #59055
Open

ENH/BUG: pd.date_range() still defaults to nanosecond resolution #59031

jorisvandenbossche opened this issue Jun 17, 2024 · 1 comment · May be fixed by #59055
Labels
Non-Nano datetime64/timedelta64 with non-nanosecond resolution
Milestone

Comments

@jorisvandenbossche
Copy link
Member

After #55901, to_datetime with strings will now infer the resolution from the data, but the related pd.date_range to create datetime data still returns nanoseconds:

In [5]: pd.date_range("2012-01-01", periods=3, freq="1min")
Out[5]: 
DatetimeIndex(['2012-01-01 00:00:00', '2012-01-01 00:01:00',
               '2012-01-01 00:02:00'],
              dtype='datetime64[ns]', freq='min')

In [6]: pd.to_datetime(['2012-01-01 00:00:00', '2012-01-01 00:01:00', '2012-01-01 00:02:00'])
Out[6]: 
DatetimeIndex(['2012-01-01 00:00:00', '2012-01-01 00:01:00',
               '2012-01-01 00:02:00'],
              dtype='datetime64[s]', freq=None)

Should we update pd.date_range as well to infer the resulting resolution from the start/stop timestamp and freq ?

(I encountered this inconsistency in the pyarrow tests, where we essentially were using both idioms to create a result and expected data, but so that started failing because of a different dtype. I also opened #58989 for that, but regardless of a possible default resolution, pd.date_range would still need to follow that as well)

@jorisvandenbossche jorisvandenbossche added the Non-Nano datetime64/timedelta64 with non-nanosecond resolution label Jun 17, 2024
@jorisvandenbossche jorisvandenbossche added this to the 3.0 milestone Jun 17, 2024
@tilovashahrin tilovashahrin linked a pull request Jun 19, 2024 that will close this issue
5 tasks
@tilovashahrin
Copy link
Contributor

Hi @jorisvandenbossche I made a few additions to the date_range function. Let me know what you think!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Non-Nano datetime64/timedelta64 with non-nanosecond resolution
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants