Skip to content

Resampling fails with equal frequency #12072

Closed
@richjoyce

Description

@richjoyce

I've got a DataFrame with a TimedeltaIndex that fails when I try to resample it to the same frequency.

Minimal working example

import pandas as pd
index = pd.timedelta_range('0', periods=9, freq='10L')
series = pd.Series(range(9), index=index)
series.resample('10L') # throws ValueError

pandas versions

INSTALLED VERSIONS
------------------
commit: None
python: 2.7.10.final.0
python-bits: 64
OS: Darwin
OS-release: 14.5.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8

pandas: 0.17.1
nose: None
pip: 1.4.1
setuptools: 1.1.6
Cython: None
numpy: 1.8.0rc1
scipy: 0.13.0b1
statsmodels: None
IPython: 2.0.0
sphinx: 1.2.2
patsy: None
dateutil: 1.5
pytz: 2013.7
blosc: None
bottleneck: None
tables: None
numexpr: 2.4.6
matplotlib: 1.3.1
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
Jinja2: None

The error thrown is:

pandas/tseries/resample.pyc in _resample_timestamps(self, kind)
    306                     axlabels.inferred_freq) == self.freq:
    307                     result = obj.copy()
--> 308                     result.index = res_index
    309                 else:
    310                     result = obj.reindex(res_index, method=self.fill_method,
... (more stacks skipped) ...
ValueError: Length mismatch: Expected axis has 9 elements, new values have 8 elements

This appears to be a problem with the logic in TimeGrouper._resample_timestamps() lines 298 to 308, the error is being thrown on line 308. It looks like res_index is being set to the wrong thing but I'm not familiar enough with the code to know how to fix properly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions