File tree 2 files changed +19
-0
lines changed 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -2323,6 +2323,8 @@ def _from_arrays(
2323
2323
2324
2324
manager = get_option ("mode.data_manager" )
2325
2325
columns = ensure_index (columns )
2326
+ if len (columns ) != len (arrays ):
2327
+ raise ValueError ("len(columns) must match len(arrays)" )
2326
2328
mgr = arrays_to_mgr (
2327
2329
arrays ,
2328
2330
columns ,
Original file line number Diff line number Diff line change @@ -433,6 +433,7 @@ def dict_to_mgr(
433
433
arrays .loc [missing ] = [val ] * missing .sum ()
434
434
435
435
arrays = list (arrays )
436
+ data_names = ensure_index (columns )
436
437
437
438
else :
438
439
keys = list (data .keys ())
@@ -738,6 +739,17 @@ def to_arrays(
738
739
) -> tuple [list [ArrayLike ], Index ]:
739
740
"""
740
741
Return list of arrays, columns.
742
+
743
+ Returns
744
+ -------
745
+ list[ArrayLike]
746
+ These will become columns in a DataFrame.
747
+ Index
748
+ This will become frame.columns.
749
+
750
+ Notes
751
+ -----
752
+ Ensures that len(result_arrays) == len(result_index).
741
753
"""
742
754
if isinstance (data , ABCDataFrame ):
743
755
# see test_from_records_with_index_data, test_from_records_bad_index_column
@@ -783,6 +795,11 @@ def to_arrays(
783
795
)
784
796
if columns is None :
785
797
columns = ibase .default_index (len (data ))
798
+ elif len (columns ) > len (data ):
799
+ raise ValueError ("len(columns) > len(data)" )
800
+ elif len (columns ) < len (data ):
801
+ # doing this here is akin to a pre-emptive reindex
802
+ data = data [: len (columns )]
786
803
return data , columns
787
804
788
805
elif isinstance (data , np .ndarray ) and data .dtype .names is not None :
You can’t perform that action at this time.
0 commit comments