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

infer_freq broken in 0.13.1 #6407

Closed
dhirschfeld opened this issue Feb 19, 2014 · 3 comments · Fixed by #6408
Closed

infer_freq broken in 0.13.1 #6407

dhirschfeld opened this issue Feb 19, 2014 · 3 comments · Fixed by #6408
Labels
Milestone

Comments

@dhirschfeld
Copy link
Contributor

In [3]: dates = pd.date_range('01-Jan-2015', '01-Jan-2016', freq='MS')
   ...: s = pd.TimeSeries(1, dates)
   ...: pd.infer_freq(s)
   ...: 
Traceback (most recent call last):

  File "<ipython-input-3-a7de7a7e9245>", line 3, in <module>
    pd.infer_freq(s)

  File "C:\dev\bin\Anaconda\lib\site-packages\pandas\tseries\frequencies.py", line 656, in infer_freq
    inferer = _FrequencyInferer(index, warn=warn)

  File "C:\dev\bin\Anaconda\lib\site-packages\pandas\tseries\frequencies.py", line 680, in __init__
    self.is_monotonic = self.index.is_monotonic

  File "C:\dev\bin\Anaconda\lib\site-packages\pandas\core\generic.py", line 1815, in __getattr__
    (type(self).__name__, name))

AttributeError: 'Series' object has no attribute 'is_monotonic'


In [4]: pd.__version__
Out[4]: '0.13.1'
@jreback
Copy link
Contributor

jreback commented Feb 19, 2014

This is actually an enhancement it didn't work in 0.12 (just gave a wrong answer!)

takes a DatetimeIndex only

In [10]: pd.infer_freq?
Type:       function
String Form:<function infer_freq at 0x3b207d0>
File:       /mnt/home/jreback/pandas/pandas/tseries/frequencies.py
Definition: pd.infer_freq(index, warn=True)
Docstring:
Infer the most likely frequency given the input index. If the frequency is
uncertain, a warning will be printed

Parameters
----------
index : DatetimeIndex
warn : boolean, default True

Returns
-------
freq : string or None
    None if no discernible frequency

works correctly on the index

In [12]: pd.infer_freq(s.index)
Out[12]: 'MS'

out of curiosity, what is your usecase for this?

@dhirschfeld
Copy link
Contributor Author

Right - UserError!

I want to create a contiguous date range at the same frequency as another series where the other series may have its freqstr equal to None. The "same frequency" is defined as the lowest frequency such that a contiguous date range will include every date in the other series - e.g. in the trivial case
microsecond frequency will interpolate any series.

@jreback
Copy link
Contributor

jreback commented Feb 20, 2014

ok..thanks

your example will raise (as its using the VALUES of the Series, otherwise this is very confusing).
Rather than return None (which IMHO is wrong). FYI their is no real distinction between TimeSeries and Series since 0.13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants