Skip to content

DatetimeIndex freq parameter is inconsistent when passing nanosecond frequencies #3524

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
cpcloud opened this issue May 3, 2013 · 4 comments
Labels
Milestone

Comments

@cpcloud
Copy link
Member

cpcloud commented May 3, 2013

This seems like a bug:

import pandas as pd
import numpy as np

def create_ns_index(start, fs, nsamples, name='time'):
    ns = int(1e9 / fs)
    dtstart = np.datetime64(start)
    dt = dtstart + np.arange(nsamples) * np.timedelta64(ns, 'ns')
    freq = ns * pd.datetools.Nano()
    return pd.DatetimeIndex(dt, freq=freq, name=name)

index = create_ns_index('2012-09-20T00:00:00', 24414, 400)
assert index.freq == '40960N'
assert index.inferred_freq == '40960N'

# try to create the same index using the period string
index = pd.DatetimeIndex(start=index[0], end=index[-1], freq=index.freq)
# throws an AttributeError

# now try to create the same index using date_range
index = pd.date_range(start=index[0], end=index[-1], freq=index.freq)
# throws the same AttributeError

# maybe it works if I use pd.datetools.Nano()
index = pd.DatetimeIndex(start=index[0], end=index[-1], freq=index.freq.n * pd.datetools.Nano())
# no such luck

# try to use periods...also fails with an ambiguous ValueError
index = pd.date_range(start=index[0], end=index[-1], periods=index.size)
@jreback
Copy link
Contributor

jreback commented May 3, 2013

i think #3060 is meant to solve this, not 100% sure though

@cpcloud
Copy link
Member Author

cpcloud commented May 3, 2013

Ok. I will leave this open until that is pushed into master.

@wuan
Copy link
Contributor

wuan commented May 7, 2013

After some minor fixes this should be solved by #3060 now. There may still be problems with non existent support for datetime64 timestamps elsewhere.

@jreback
Copy link
Contributor

jreback commented Sep 22, 2013

closing in favor of #1812

@jreback jreback closed this as completed Sep 22, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants