@@ -929,7 +929,9 @@ def get_rec_attributes(recording):
929929 return rec_attributes
930930
931931
932- def do_recording_attributes_match (recording1 , recording2_attributes ) -> bool :
932+ def do_recording_attributes_match (
933+ recording1 : "BaseRecording" , recording2_attributes : bool , check_dtype : bool = True
934+ ) -> tuple [bool , str ]:
933935 """
934936 Check if two recordings have the same attributes
935937
@@ -939,22 +941,43 @@ def do_recording_attributes_match(recording1, recording2_attributes) -> bool:
939941 The first recording object
940942 recording2_attributes : dict
941943 The recording attributes to test against
944+ check_dtype : bool, default: True
945+ If True, check if the recordings have the same dtype
942946
943947 Returns
944948 -------
945949 bool
946950 True if the recordings have the same attributes
951+ str
952+ A string with the exception message with the attributes that do not match
947953 """
948954 recording1_attributes = get_rec_attributes (recording1 )
949955 recording2_attributes = deepcopy (recording2_attributes )
950956 recording1_attributes .pop ("properties" )
951957 recording2_attributes .pop ("properties" )
952958
953- return (
954- np .array_equal (recording1_attributes ["channel_ids" ], recording2_attributes ["channel_ids" ])
955- and recording1_attributes ["sampling_frequency" ] == recording2_attributes ["sampling_frequency" ]
956- and recording1_attributes ["num_channels" ] == recording2_attributes ["num_channels" ]
957- and recording1_attributes ["num_samples" ] == recording2_attributes ["num_samples" ]
958- and recording1_attributes ["is_filtered" ] == recording2_attributes ["is_filtered" ]
959- and recording1_attributes ["dtype" ] == recording2_attributes ["dtype" ]
960- )
959+ attributes_match = True
960+ non_matching_attrs = []
961+
962+ if not np .array_equal (recording1_attributes ["channel_ids" ], recording2_attributes ["channel_ids" ]):
963+ non_matching_attrs .append ("channel_ids" )
964+ if not recording1_attributes ["sampling_frequency" ] == recording2_attributes ["sampling_frequency" ]:
965+ non_matching_attrs .append ("sampling_frequency" )
966+ if not recording1_attributes ["num_channels" ] == recording2_attributes ["num_channels" ]:
967+ non_matching_attrs .append ("num_channels" )
968+ if not recording1_attributes ["num_samples" ] == recording2_attributes ["num_samples" ]:
969+ non_matching_attrs .append ("num_samples" )
970+ # dtype is optional
971+ if "dtype" in recording1_attributes and "dtype" in recording2_attributes :
972+ if check_dtype :
973+ if not recording1_attributes ["dtype" ] == recording2_attributes ["dtype" ]:
974+ non_matching_attrs .append ("dtype" )
975+
976+ if len (non_matching_attrs ) > 0 :
977+ attributes_match = False
978+ exception_str = f"Recordings do not match in the following attributes: { non_matching_attrs } "
979+ else :
980+ attributes_match = True
981+ exception_str = ""
982+
983+ return attributes_match , exception_str
0 commit comments