-  
-   Notifications  You must be signed in to change notification settings 
- Fork 19.2k
Closed
Labels
Error ReportingIncorrect or improved errors from pandasIncorrect or improved errors from pandasSparseSparse Data TypeSparse Data Typegood first issue
Milestone
Description
see also #5289
Code Sample, a copy-pastable example if possible
import numpy as np import pandas as pd data = {'A': [np.nan, np.nan, np.nan, 0, 1, 2, 3, 4, 5, 6], 'B': [0, 1, 2, np.nan, np.nan, np.nan, 3, 4, 5, 6], 'C': np.arange(10, dtype=np.float64), 'D': [0, 1, 2, 3, 4, 5, np.nan, np.nan, np.nan, np.nan]} dates = pd.bdate_range('1/1/2011', periods=10) float_frame = pd.SparseDataFrame(data, index=dates, default_kind='block') N = len(float_frame) float_frame['foo'] = np.random.randn(N - 1)Problem description
--------------------------------------------------------------------------- AssertionError Traceback (most recent call last) <ipython-input-8-0a4f051f0d7a> in <module> 8 float_frame = pd.SparseDataFrame(data, index=dates, default_kind='block') 9 N = len(float_frame) ---> 10 float_frame['foo'] = np.random.randn(N - 1) ~\Anaconda3\lib\site-packages\pandas\core\frame.py in __setitem__(self, key, value) 3117 else: 3118 # set column -> 3119 self._set_item(key, value) 3120 3121 def _setitem_slice(self, key, value): ~\Anaconda3\lib\site-packages\pandas\core\frame.py in _set_item(self, key, value) 3192 3193 self._ensure_valid_index(value) -> 3194 value = self._sanitize_column(key, value) 3195 NDFrame._set_item(self, key, value) 3196 ~\Anaconda3\lib\site-packages\pandas\core\sparse\frame.py in _sanitize_column(self, key, value, **kwargs) 418 else: 419 if len(value) != len(self.index): --> 420 raise AssertionError('Length of values does not match ' 421 'length of index') 422 clean = sp_maker(value) AssertionError: Length of values does not match length of indexExpected Output
ValueError: Length of values does not match length of indexOutput of pd.show_versions()
 INSTALLED VERSIONS
commit: None
 python: 3.7.1.final.0
 python-bits: 64
 OS: Windows
 OS-release: 10
 machine: AMD64
 processor: Intel64 Family 6 Model 158 Stepping 9, GenuineIntel
 byteorder: little
 LC_ALL: None
 LANG: None
 LOCALE: None.None
pandas: 0.23.4
 pytest: 4.0.2
 pip: 18.1
 setuptools: 40.6.3
 Cython: 0.29.2
 numpy: 1.15.4
 scipy: 1.1.0
 pyarrow: None
 xarray: None
 IPython: 7.2.0
 sphinx: 1.8.2
 patsy: 0.5.1
 dateutil: 2.7.5
 pytz: 2018.7
 blosc: None
 bottleneck: 1.2.1
 tables: 3.4.4
 numexpr: 2.6.8
 feather: None
 matplotlib: 3.0.2
 openpyxl: 2.5.12
 xlrd: 1.2.0
 xlwt: 1.3.0
 xlsxwriter: 1.1.2
 lxml: 4.2.5
 bs4: 4.6.3
 html5lib: 1.0.1
 sqlalchemy: 1.2.15
 pymysql: None
 psycopg2: None
 jinja2: 2.10
 s3fs: None
 fastparquet: None
 pandas_gbq: None
 pandas_datareader: None
Metadata
Metadata
Assignees
Labels
Error ReportingIncorrect or improved errors from pandasIncorrect or improved errors from pandasSparseSparse Data TypeSparse Data Typegood first issue