Skip to content

Unclear error produced by resampling with NaT in Index #13020

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
patricktokeeffe opened this issue Apr 28, 2016 · 2 comments
Closed

Unclear error produced by resampling with NaT in Index #13020

patricktokeeffe opened this issue Apr 28, 2016 · 2 comments
Labels
Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Resample resample method Testing pandas testing functions or related to the test suite
Milestone

Comments

@patricktokeeffe
Copy link
Contributor

Similar to #4746, trying to resample with an index containing NaT produces rather ambiguous error messages of the form:

ValueError: Shape of passed values is (2, 5), indices imply (2, 4)

Something like cannot resample from index containing Not-a-Time (NaT) would be more helpful to users.

MWE

import pandas as pd
import numpy as np

times = pd.DatetimeIndex(['20160428T110000',
                          '20160428T110001',
                          '20160428T110002',
                          '20160428T110003',
                          '20160428T110004',
                          pd.NaT,
                          '20160428T110001',
                          '20160428T110002',
                          '20160428T110003',
                          '20160428T110004'])

df = pd.DataFrame(np.random.randn(10,2),
                  index=times,
                  columns=['A', 'B'])
df.resample('3s')

This example index contains duplicate values, but results are the same w/ or w/o them.

output of pd.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 2.7.9.final.0
python-bits: 32
OS: Windows
OS-release: 7
machine: AMD64
processor: Intel64 Family 6 Model 23 Stepping 10, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None

pandas: 0.15.2
nose: 1.3.4
Cython: 0.21.1
numpy: 1.8.2
scipy: 0.14.0
statsmodels: 0.6.1
IPython: 2.3.1
sphinx: 1.2.3
patsy: 0.3.0
dateutil: 2.3
pytz: 2014.10
bottleneck: None
tables: 3.1.1
numexpr: 2.4
matplotlib: 1.4.2
openpyxl: None
xlrd: 0.9.3
xlwt: None
xlsxwriter: 0.6.4
lxml: 3.4.1
bs4: 4.3.2
html5lib: None
httplib2: None
apiclient: None
rpy2: 2.5.2
sqlalchemy: 0.9.8
pymysql: None
psycopg2: None
@jreback
Copy link
Contributor

jreback commented Apr 28, 2016

so this works in master. Note the syntax change in 0.18.0 (you have a quite old version).

In [23]: df.resample('3s').mean()
Out[23]: 
                            A         B
2016-04-28 11:00:00  0.633764 -0.551855
2016-04-28 11:00:03  0.024339  0.041184

I don't know if we are specifically testing for this. Welcome to have some confirming tests.

@jreback jreback added Testing pandas testing functions or related to the test suite Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Difficulty Novice Resample resample method labels Apr 28, 2016
@jreback jreback added this to the 0.18.2 milestone Apr 28, 2016
@jreback
Copy link
Contributor

jreback commented Apr 28, 2016

In [24]: df = pd.DataFrame(np.repeat(np.arange(10),2).reshape(10,-1),columns=list('AB'),index=times)

In [25]: df
Out[25]: 
                     A  B
2016-04-28 11:00:00  0  0
2016-04-28 11:00:01  1  1
2016-04-28 11:00:02  2  2
2016-04-28 11:00:03  3  3
2016-04-28 11:00:04  4  4
NaT                  5  5
2016-04-28 11:00:01  6  6
2016-04-28 11:00:02  7  7
2016-04-28 11:00:03  8  8
2016-04-28 11:00:04  9  9

In [26]: df.resample('3s').mean()
Out[26]: 
                       A    B
2016-04-28 11:00:00  3.2  3.2
2016-04-28 11:00:03  6.0  6.0

evectant pushed a commit to evectant/pandas that referenced this issue May 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Resample resample method Testing pandas testing functions or related to the test suite
Projects
None yet
Development

No branches or pull requests

2 participants