Skip to content

BUG: date_range ignores nanoseconds component of DateOffset frequency #44393

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

Closed
3 tasks done
shwina opened this issue Nov 11, 2021 · 1 comment
Closed
3 tasks done

BUG: date_range ignores nanoseconds component of DateOffset frequency #44393

shwina opened this issue Nov 11, 2021 · 1 comment
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@shwina
Copy link
Contributor

shwina commented Nov 11, 2021

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the master branch of pandas.

Reproducible Example

import pandas as pd

pd.date_range(start='2001-01-01', freq=pd.DateOffset(nanoseconds=1), periods=3).to_numpy()

Issue Description

Greetings!

When specifying the frequency as a DateOffset object, Pandas seems to ignore the frequency entirely if it consists solely of a nanoseconds component:

In [6]: pd.date_range(start='2001-01-01', freq='1ns', periods=3).to_numpy()
Out[6]:
array(['2001-01-01T00:00:00.000000000', '2001-01-01T00:00:00.000000001',
       '2001-01-01T00:00:00.000000002'], dtype='datetime64[ns]')

In [7]: pd.date_range(start='2001-01-01', freq=pd.DateOffset(nanoseconds=1), periods=3).to_numpy()
Out[7]:
array(['2001-01-01T00:00:00.000000000', '2001-01-02T00:00:00.000000000',
       '2001-01-03T00:00:00.000000000'], dtype='datetime64[ns]')

or, if it consists of multiple components, ignores the nanoseconds part:

In [8]: pd.date_range(start='2001-01-01', freq=pd.DateOffset(days=1, nanoseconds=1), periods=3).to_numpy()
Out[8]:
array(['2001-01-01T00:00:00.000000000', '2001-01-02T00:00:00.000000000',
       '2001-01-03T00:00:00.000000000'], dtype='datetime64[ns]')

Expected Behavior

import pandas as pd
import numpy as np

expect = pd.date_range(start='2001-01-01', freq='1ns', periods=3).to_numpy().astype('int64')
got = pd.date_range(start='2001-01-01', freq=pd.DateOffset(nanoseconds=1), periods=3).to_numpy().astype('int64')
np.testing.assert_equal(expect, got)

Installed Versions

Replace this line with the output of pd.show_versions()

@shwina shwina added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Nov 11, 2021
@mroeschke
Copy link
Member

Thanks for the report. I believe the core issue was reported in #43892 so closing to close this in favor of that.

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 a pandas team member
Projects
None yet
Development

No branches or pull requests

2 participants