@@ -1323,9 +1323,27 @@ def test_concat(df_simple):
13231323 # add new columns
13241324 navdata = navdata_1 .concat (navdata_1 )
13251325 assert navdata .shape == (4 ,12 )
1326+ pandas_equiv = pd .concat ((df_simple ,df_simple ),axis = 0 )
1327+ pandas_equiv .reset_index (drop = True , inplace = True )
1328+ pd .testing .assert_frame_equal (pandas_equiv .sort_index (axis = 1 ),
1329+ navdata .pandas_df ().sort_index (axis = 1 ),
1330+ check_index_type = False ,
1331+ check_dtype = False )
1332+
13261333 # add new rows
13271334 navdata = navdata_1 .concat (navdata_1 ,axis = 0 )
13281335 assert navdata .shape == (8 ,6 )
1336+ mapper = {"names" :"names_0" ,
1337+ "floats" :"floats_0" ,
1338+ "integers" :"integers_0" ,
1339+ "strings" :"strings_0" }
1340+ df_simple_2 = df_simple .rename (mapper ,axis = 1 )
1341+ pandas_equiv = pd .concat ((df_simple ,df_simple_2 ),axis = 1 )
1342+ pandas_equiv .reset_index (drop = True , inplace = True )
1343+ pd .testing .assert_frame_equal (pandas_equiv .sort_index (axis = 1 ),
1344+ navdata .pandas_df ().sort_index (axis = 1 ),
1345+ check_index_type = False ,
1346+ check_dtype = False )
13291347
13301348 # test multiple rows with the same name
13311349 navdata_long = navdata_1 .copy ()
@@ -1337,10 +1355,33 @@ def test_concat(df_simple):
13371355 # add semi new columns
13381356 navdata = navdata_1 .concat (navdata_2 )
13391357 assert navdata .shape == (6 ,12 )
1358+ assert np .all (np .isnan (navdata ["floats" ][- 6 :]))
1359+ assert np .all (navdata ["names" ][- 6 :] == np .array ([np .nan ]).astype (str )[0 ])
1360+ assert np .all (np .isnan (navdata ["decimals" ][:6 ]))
1361+ assert np .all (navdata ["words" ][:6 ] == np .array ([np .nan ]).astype (str )[0 ])
1362+
1363+ # add semi new columns in opposite order
1364+ navdata = navdata_2 .concat (navdata_1 )
1365+ assert navdata .shape == (6 ,12 )
1366+ assert np .all (np .isnan (navdata ["floats" ][:6 ]))
1367+ assert np .all (navdata ["names" ][:6 ] == np .array ([np .nan ]).astype (str )[0 ])
1368+ assert np .all (np .isnan (navdata ["decimals" ][- 6 :]))
1369+ assert np .all (navdata ["words" ][- 6 :] == np .array ([np .nan ]).astype (str )[0 ])
13401370
13411371 # add as new rows
1342- navdata_b = navdata_1 .concat (navdata_2 ,axis = 0 )
1343- assert navdata_b .shape == (8 ,6 )
1372+ navdata = navdata_1 .concat (navdata_2 ,axis = 0 )
1373+ assert navdata .shape == (8 ,6 )
1374+ mapper = {"names" :"words" ,
1375+ "floats" :"decimals" ,
1376+ "integers" :"integers_0" ,
1377+ "strings" :"strings_0" }
1378+ df_simple_2 = df_simple .rename (mapper ,axis = 1 )
1379+ pandas_equiv = pd .concat ((df_simple ,df_simple_2 ),axis = 1 )
1380+ pandas_equiv .reset_index (drop = True , inplace = True )
1381+ pd .testing .assert_frame_equal (pandas_equiv .sort_index (axis = 1 ),
1382+ navdata .pandas_df ().sort_index (axis = 1 ),
1383+ check_index_type = False ,
1384+ check_dtype = False )
13441385
13451386def test_concat_fails (df_simple ):
13461387 """Test when concat should fail.
0 commit comments