Skip to content

Exception when resampling ends on a DST change date #8653

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
lmancini opened this issue Oct 27, 2014 · 5 comments
Closed

Exception when resampling ends on a DST change date #8653

lmancini opened this issue Oct 27, 2014 · 5 comments
Labels
Bug Duplicate Report Duplicate issue or pull request Resample resample method Timezones Timezone data dtype
Milestone

Comments

@lmancini
Copy link

Hi all, I'm experiencing an exception when calling resample('D', how='mean') on a Series or Dataframe whose index (datetime-based) ends just on a DST change date.

As a workaround, I'm currently try/except-ing the ValueError and eventually adding a np.nan datapoint at the end of the series (effectively "walking over" the DST change date). At that point I call resample which completes correctly and filters away the np.nan datapoint anyway.

Snippet [1] reproduces the bug, calling resample on a short series which ends on Oct 26th, which was the DST change date for Europe/Rome. Raised exception is [2]. If relevant, [3] shows the installed versions info.

[1]

import datetime
import pytz as tz
import pandas as pd

rome = tz.timezone('Europe/Rome')

dr = []
for i in range(2):
    dp = datetime.datetime(2014, 10, 25) + datetime.timedelta(days=i)
    dr.append(rome.localize(dp))

series = {}
for i, ddr in enumerate(dr):
    series[ddr] = i * 10

s1 = pd.Series(series)
s1 = s1.resample('D', how='mean')

[2]


File "resample_this.py", line 18, in <module>
    s1 = s1.resample('D', how='mean')
  File "pandas/core/generic.py", line 2980, in resample
    return sampler.resample(self).__finalize__(self)
  File "pandas/tseries/resample.py", line 85, in resample
    rs = self._resample_timestamps()
  File "pandas/tseries/resample.py", line 314, in _resample_timestamps
    result = grouped.aggregate(self._agg_method)
  File "pandas/core/groupby.py", line 2265, in aggregate
    return getattr(self, func_or_funcs)(*args, **kwargs)
  File "pandas/core/groupby.py", line 693, in mean
    return self._python_agg_general(f)
  File "pandas/core/groupby.py", line 1125, in _python_agg_general
    return self._wrap_aggregated_output(output)
  File "pandas/core/groupby.py", line 2332, in _wrap_aggregated_output
    return Series(output, index=index, name=name)
  File "pandas/core/series.py", line 212, in __init__
    data = SingleBlockManager(data, index, fastpath=True)
  File "pandas/core/internals.py", line 3326, in __init__
    ndim=1, fastpath=True)
  File "pandas/core/internals.py", line 2060, in make_block
    placement=placement)
  File "pandas/core/internals.py", line 75, in __init__
    len(self.values), len(self.mgr_locs)))
ValueError: Wrong number of items passed 2, placement implies 1
INSTALLED VERSIONS
------------------
commit: None
python: 2.7.6.final.0
python-bits: 64
OS: Darwin
OS-release: 13.4.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: None

pandas: 0.15.0
nose: None
Cython: None
numpy: 1.9.0
scipy: None
statsmodels: None
IPython: None
sphinx: 1.2.3
patsy: None
dateutil: 1.5
pytz: 2014.7
bottleneck: None
tables: None
numexpr: None
matplotlib: None
openpyxl: 2.1.1
xlrd: None
xlwt: 0.7.5
xlsxwriter: None
lxml: 3.4.0
bs4: 4.3.2
html5lib: None
httplib2: 0.9
apiclient: None
rpy2: None
sqlalchemy: None
pymysql: None
psycopg2: None
@ischwabacher
Copy link
Contributor

xref #8601

@jreback
Copy link
Contributor

jreback commented Oct 27, 2014

closing this as a dupe of #8601 (but will xref in the top because its a nice example)

@jreback jreback closed this as completed Oct 27, 2014
@jreback jreback added Bug Duplicate Report Duplicate issue or pull request Resample resample method Timezones Timezone data dtype labels Oct 27, 2014
@jreback jreback added this to the 0.15.1 milestone Oct 27, 2014
@ischwabacher
Copy link
Contributor

Looking again, this is a different exception from #8601; it might not be the same issue.

@jreback jreback reopened this Oct 27, 2014
@jreback
Copy link
Contributor

jreback commented Oct 27, 2014

ok, then will reopen!

@jreback
Copy link
Contributor

jreback commented Nov 6, 2014

closing as dupe of #5172 for now

@jreback jreback closed this as completed Nov 6, 2014
@jreback jreback added the Duplicate Report Duplicate issue or pull request label Nov 6, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Duplicate Report Duplicate issue or pull request Resample resample method Timezones Timezone data dtype
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants