@@ -1167,26 +1167,59 @@ def assert_frame_equal(left, right, check_dtype=True,
11671167
11681168
11691169def assert_panelnd_equal (left , right ,
1170+ check_dtype = True ,
11701171 check_panel_type = False ,
11711172 check_less_precise = False ,
11721173 assert_func = assert_frame_equal ,
1173- check_names = False ):
1174+ check_names = False ,
1175+ by_blocks = False ):
1176+ """Check that left and right Panels are equal.
1177+
1178+ Parameters
1179+ ----------
1180+ left : Panel (or nd)
1181+ right : Panel (or nd)
1182+ check_dtype : bool, default True
1183+ Whether to check the Panel dtype is identical.
1184+ check_panel_type : bool, default False
1185+ Whether to check the Panel class is identical.
1186+ check_less_precise : bool, default False
1187+ Specify comparison precision. Only used when check_exact is False.
1188+ 5 digits (False) or 3 digits (True) after decimal points are compared.
1189+ assert_func : function for comparing data
1190+ check_names : bool, default True
1191+ Whether to check the Index names attribute.
1192+ by_blocks : bool, default False
1193+ Specify how to compare internal data. If False, compare by columns.
1194+ If True, compare by blocks.
1195+ """
1196+
11741197 if check_panel_type :
11751198 assertIsInstance (left , type (right ))
11761199
1177- for axis in [ 'items' , 'major_axis' , 'minor_axis' ] :
1200+ for axis in left . _AXIS_ORDERS :
11781201 left_ind = getattr (left , axis )
11791202 right_ind = getattr (right , axis )
11801203 assert_index_equal (left_ind , right_ind , check_names = check_names )
11811204
1182- for i , item in enumerate (left ._get_axis (0 )):
1183- assert item in right , "non-matching item (right) '%s'" % item
1184- litem = left .iloc [i ]
1185- ritem = right .iloc [i ]
1186- assert_func (litem , ritem , check_less_precise = check_less_precise )
1205+ if by_blocks :
1206+ rblocks = right .blocks
1207+ lblocks = left .blocks
1208+ for dtype in list (set (list (lblocks .keys ()) + list (rblocks .keys ()))):
1209+ assert dtype in lblocks
1210+ assert dtype in rblocks
1211+ array_equivalent (lblocks [dtype ].values , rblocks [dtype ].values )
1212+ else :
1213+
1214+ # can potentially be slow
1215+ for i , item in enumerate (left ._get_axis (0 )):
1216+ assert item in right , "non-matching item (right) '%s'" % item
1217+ litem = left .iloc [i ]
1218+ ritem = right .iloc [i ]
1219+ assert_func (litem , ritem , check_less_precise = check_less_precise )
11871220
1188- for i , item in enumerate (right ._get_axis (0 )):
1189- assert item in left , "non-matching item (left) '%s'" % item
1221+ for i , item in enumerate (right ._get_axis (0 )):
1222+ assert item in left , "non-matching item (left) '%s'" % item
11901223
11911224# TODO: strangely check_names fails in py3 ?
11921225_panel_frame_equal = partial (assert_frame_equal , check_names = False )
0 commit comments