@@ -232,8 +232,9 @@ def _compare_xarray_dataarray(
232232 if actual .shape != expected .shape :
233233 issues .append (f"Shape mismatch: { actual .shape } != { expected .shape } " )
234234 compatible = len (issues ) == 0
235+ is_numerical_data = numpy .issubdtype (actual .dtype , numpy .number ) and numpy .issubdtype (expected .dtype , numpy .number )
235236 try :
236- if pixel_tolerance and compatible :
237+ if pixel_tolerance and compatible and is_numerical_data :
237238 threshold = abs (expected * rtol ) + atol
238239 bad_pixels = abs (actual * 1.0 - expected * 1.0 ) > threshold
239240 percentage_bad_pixels = bad_pixels .mean ().item () * 100
@@ -320,6 +321,7 @@ def assert_xarray_dataset_allclose(
320321 * ,
321322 rtol : float = _DEFAULT_RTOL ,
322323 atol : float = _DEFAULT_ATOL ,
324+ pixel_tolerance : float = _DEFAULT_PIXELTOL ,
323325):
324326 """
325327 Assert that two Xarray ``DataSet`` instances are equal (with tolerance).
@@ -335,7 +337,9 @@ def assert_xarray_dataset_allclose(
335337 .. warning::
336338 This function is experimental and subject to change.
337339 """
338- issues = _compare_xarray_datasets (actual = actual , expected = expected , rtol = rtol , atol = atol )
340+ issues = _compare_xarray_datasets (
341+ actual = actual , expected = expected , rtol = rtol , atol = atol , pixel_tolerance = pixel_tolerance
342+ )
339343 if issues :
340344 raise AssertionError ("\n " .join (issues ))
341345
0 commit comments