@@ -859,7 +859,7 @@ def __len__(self, n):
859859 # GH 4297
860860 # support Array
861861 import array
862- result = DataFrame . from_items ([( 'A' , array .array ('i' , range (10 )))] )
862+ result = DataFrame ({ 'A' : array .array ('i' , range (10 ))} )
863863 expected = DataFrame ({'A' : list (range (10 ))})
864864 tm .assert_frame_equal (result , expected , check_dtype = False )
865865
@@ -1163,44 +1163,55 @@ def test_constructor_manager_resize(self):
11631163
11641164 def test_constructor_from_items (self ):
11651165 items = [(c , self .frame [c ]) for c in self .frame .columns ]
1166- recons = DataFrame .from_items (items )
1166+ with tm .assert_produces_warning (FutureWarning ,
1167+ check_stacklevel = False ):
1168+ recons = DataFrame .from_items (items )
11671169 tm .assert_frame_equal (recons , self .frame )
11681170
11691171 # pass some columns
1170- recons = DataFrame .from_items (items , columns = ['C' , 'B' , 'A' ])
1172+ with tm .assert_produces_warning (FutureWarning ,
1173+ check_stacklevel = False ):
1174+ recons = DataFrame .from_items (items , columns = ['C' , 'B' , 'A' ])
11711175 tm .assert_frame_equal (recons , self .frame .loc [:, ['C' , 'B' , 'A' ]])
11721176
11731177 # orient='index'
11741178
11751179 row_items = [(idx , self .mixed_frame .xs (idx ))
11761180 for idx in self .mixed_frame .index ]
1177-
1178- recons = DataFrame .from_items (row_items ,
1179- columns = self .mixed_frame .columns ,
1180- orient = 'index' )
1181+ with tm .assert_produces_warning (FutureWarning ,
1182+ check_stacklevel = False ):
1183+ recons = DataFrame .from_items (row_items ,
1184+ columns = self .mixed_frame .columns ,
1185+ orient = 'index' )
11811186 tm .assert_frame_equal (recons , self .mixed_frame )
11821187 assert recons ['A' ].dtype == np .float64
11831188
11841189 with tm .assert_raises_regex (TypeError ,
11851190 "Must pass columns with "
11861191 "orient='index'" ):
1187- DataFrame .from_items (row_items , orient = 'index' )
1192+ with tm .assert_produces_warning (FutureWarning ,
1193+ check_stacklevel = False ):
1194+ DataFrame .from_items (row_items , orient = 'index' )
11881195
11891196 # orient='index', but thar be tuples
11901197 arr = lib .list_to_object_array (
11911198 [('bar' , 'baz' )] * len (self .mixed_frame ))
11921199 self .mixed_frame ['foo' ] = arr
11931200 row_items = [(idx , list (self .mixed_frame .xs (idx )))
11941201 for idx in self .mixed_frame .index ]
1195- recons = DataFrame .from_items (row_items ,
1196- columns = self .mixed_frame .columns ,
1197- orient = 'index' )
1202+ with tm .assert_produces_warning (FutureWarning ,
1203+ check_stacklevel = False ):
1204+ recons = DataFrame .from_items (row_items ,
1205+ columns = self .mixed_frame .columns ,
1206+ orient = 'index' )
11981207 tm .assert_frame_equal (recons , self .mixed_frame )
11991208 assert isinstance (recons ['foo' ][0 ], tuple )
12001209
1201- rs = DataFrame .from_items ([('A' , [1 , 2 , 3 ]), ('B' , [4 , 5 , 6 ])],
1202- orient = 'index' ,
1203- columns = ['one' , 'two' , 'three' ])
1210+ with tm .assert_produces_warning (FutureWarning ,
1211+ check_stacklevel = False ):
1212+ rs = DataFrame .from_items ([('A' , [1 , 2 , 3 ]), ('B' , [4 , 5 , 6 ])],
1213+ orient = 'index' ,
1214+ columns = ['one' , 'two' , 'three' ])
12041215 xp = DataFrame ([[1 , 2 , 3 ], [4 , 5 , 6 ]], index = ['A' , 'B' ],
12051216 columns = ['one' , 'two' , 'three' ])
12061217 tm .assert_frame_equal (rs , xp )
@@ -1210,12 +1221,28 @@ def test_constructor_from_items_scalars(self):
12101221 with tm .assert_raises_regex (ValueError ,
12111222 'The value in each \(key, value\) '
12121223 'pair must be an array, Series, or dict' ):
1213- DataFrame .from_items ([('A' , 1 ), ('B' , 4 )])
1224+ with tm .assert_produces_warning (FutureWarning ,
1225+ check_stacklevel = False ):
1226+ DataFrame .from_items ([('A' , 1 ), ('B' , 4 )])
12141227
12151228 with tm .assert_raises_regex (ValueError ,
12161229 'The value in each \(key, value\) '
12171230 'pair must be an array, Series, or dict' ):
1218- DataFrame .from_items ([('A' , 1 ), ('B' , 2 )], columns = ['col1' ],
1231+ with tm .assert_produces_warning (FutureWarning ,
1232+ check_stacklevel = False ):
1233+ DataFrame .from_items ([('A' , 1 ), ('B' , 2 )], columns = ['col1' ],
1234+ orient = 'index' )
1235+
1236+ def test_from_items_deprecation (self ):
1237+ # GH 17320
1238+ with tm .assert_produces_warning (FutureWarning ,
1239+ check_stacklevel = False ):
1240+ DataFrame .from_items ([('A' , [1 , 2 , 3 ]), ('B' , [4 , 5 , 6 ])])
1241+
1242+ with tm .assert_produces_warning (FutureWarning ,
1243+ check_stacklevel = False ):
1244+ DataFrame .from_items ([('A' , [1 , 2 , 3 ]), ('B' , [4 , 5 , 6 ])],
1245+ columns = ['col1' , 'col2' , 'col3' ],
12191246 orient = 'index' )
12201247
12211248 def test_constructor_mix_series_nonseries (self ):
@@ -1244,13 +1271,17 @@ def test_constructor_column_duplicates(self):
12441271
12451272 tm .assert_frame_equal (df , edf )
12461273
1247- idf = DataFrame .from_items (
1248- [('a' , [8 ]), ('a' , [5 ])], columns = ['a' , 'a' ])
1274+ with tm .assert_produces_warning (FutureWarning ,
1275+ check_stacklevel = False ):
1276+ idf = DataFrame .from_items ([('a' , [8 ]), ('a' , [5 ])],
1277+ columns = ['a' , 'a' ])
12491278 tm .assert_frame_equal (idf , edf )
12501279
1251- pytest .raises (ValueError , DataFrame .from_items ,
1252- [('a' , [8 ]), ('a' , [5 ]), ('b' , [6 ])],
1253- columns = ['b' , 'a' , 'a' ])
1280+ with tm .assert_produces_warning (FutureWarning ,
1281+ check_stacklevel = False ):
1282+ pytest .raises (ValueError , DataFrame .from_items ,
1283+ [('a' , [8 ]), ('a' , [5 ]), ('b' , [6 ])],
1284+ columns = ['b' , 'a' , 'a' ])
12541285
12551286 def test_constructor_empty_with_string_dtype (self ):
12561287 # GH 9428
0 commit comments