2017-04-02 6 views
1

パンダの現在のバージョンを使用してnumpyの日付ベクトルを逆方向​​に埋め込むのに問題があります。同じコードは以前のバージョンで動作します。以下は私の問題を示していますpandas DataFrameエラー "タプルインデックスが範囲外です"

古いバージョン(0.7.3)が

C:\WINDOWS\system32>pip show pandas 
Name: pandas 
Version: 0.7.3 
Summary: Powerful data structures for data analysis and statistics 
Home-page: http://pandas.pydata.org 
Author: The PyData Development Team 
Author-email: [email protected] 
License: BSD 
Location: c:\program files\python\python27\lib\site-packages 
Requires: python-dateutil, numpy 

C:\WINDOWS\system32>python 
Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:24:40) [MSC v.1500 64 bit (AMD64)] on win32 
Type "help", "copyright", "credits" or "license" for more information. 
>>> 
>>> d=np.array([None, None, None, None, dt.now(), None]) 
>>> b = DataFrame(d) 
>>> b.fillna(method='backfill') 
          0 
0 2017-04-02 12:21:18.175000 
1 2017-04-02 12:21:18.175000 
2 2017-04-02 12:21:18.175000 
3 2017-04-02 12:21:18.175000 
4 2017-04-02 12:21:18.175000 
5      None 
>>> 

現在vesion(0.19.2時点)が動作しない動作します。

C:\WINDOWS\system32>pip show pandas 
Name: pandas 
Version: 0.19.2 
Summary: Powerful data structures for data analysis, time series,and statistics 
Home-page: http://pandas.pydata.org 
Author: The PyData Development Team 
Author-email: [email protected] 
License: BSD 
Location: c:\program files\python\python27\lib\site-packages 
Requires: pytz, python-dateutil, numpy 


C:\WINDOWS\system32>python 
Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:24:40) [MSC v.1500 64 bit (AMD64)] on win32 
Type "help", "copyright", "credits" or "license" for more information. 
>>> from datetime import datetime as dt 
>>> import numpy as np 
>>> from pandas import DataFrame 
>>> d=np.array([None, None, None, None, dt.now(), None]) 
>>> b = DataFrame(d) 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "C:\Program Files\Python\Python27\lib\site-packages\pandas\core\frame.py", line 297, in __init__ 
    copy=copy) 
    File "C:\Program Files\Python\Python27\lib\site-packages\pandas\core\frame.py", line 474, in _init_ndarray 
    return create_block_manager_from_blocks([values], [columns, index]) 
    File "C:\Program Files\Python\Python27\lib\site-packages\pandas\core\internals.py", line 4256, in create_block_manager_from_blocks 
    construction_error(tot_items, blocks[0].shape[1:], axes, e) 
    File "C:\Program Files\Python\Python27\lib\site-packages\pandas\core\internals.py", line 4230, in construction_error 
    if block_shape[0] == 0: 
IndexError: tuple index out of range 
>>> 

私が何かをしています間違っていると思うのですが、パンダのバグでしょうか?バグの場合はどうすれば報告できますか?

EDIT:このパンダとバグ報告として提出された、次のマイナーrelaseに固定されます(0.19.3)

答えて

2

DataFrame(d)失敗し、私はなぜわからないんだけど、Series(d)作品、あなたがこれを行うことができます:

ある
pd.DataFrame({0:d}) 

を、明示的にdシリーズは、それが暗黙のうちに古代の0.7バージョンでは何をやっていたである、0と呼ばれることパンダを教えてください。

あなたがバグを報告したいならば、あなたは、単にこの作品と言うことができます:

pd.DataFrame([None, None, datetime.datetime.now()]) 

しかし、これは失敗します。明示的に指定(またはキャスト)する

pd.DataFrame([None, None, None, datetime.datetime.now()]) 
+0

そのお返事ありがとうございます。これを報告する場所を教えていただけますか?あなたのテストで何が起こっているのかを説明することもできますか?なぜ、1つは働き、もう1つはないのですか? –

+0

@リチャードB:パンダの問題追跡は、ここにあります:https://github.com/pandas-dev/pandas/issues –

0

てみてくださいdtype

In [18]: d=np.array([None, None, None, None, pd.datetime.now(), None]) 

In [19]: b = DataFrame(d.astype('datetime64[ms]')) 

In [20]: b 
Out[20]: 
         0 
0      NaT 
1      NaT 
2      NaT 
3      NaT 
4 2017-04-02 20:34:20.381 
5      NaT 

In [21]: b.bfill() 
Out[21]: 
         0 
0 2017-04-02 20:34:20.381 
1 2017-04-02 20:34:20.381 
2 2017-04-02 20:34:20.381 
3 2017-04-02 20:34:20.381 
4 2017-04-02 20:34:20.381 
5      NaT 
関連する問題