Skip to content

Commit

Permalink
narrow dtypes
Browse files Browse the repository at this point in the history
  • Loading branch information
TomNicholas committed Dec 31, 2023
1 parent c07c690 commit d2b35c5
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions xarray/testing/duckarrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ def test_construct_variable(self, data) -> None:
self.check(var, arr)


def is_real_floating(dtype):
return np.issubdtype(dtype, np.number) and np.issubdtype(dtype, np.floating)


class ReduceTests:
dtypes = xrst.supported_dtypes()

Expand Down Expand Up @@ -103,34 +107,35 @@ def check_reduce(self, var, op, dim, *args, **kwargs):
assert_identical(actual, expected)

@pytest.mark.parametrize(
"method",
"method, dtype_assumption",

Check failure on line 110 in xarray/testing/duckarrays.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.10 all-but-dask

TestReductions.test_reduce_variable[sum-is_real_floating] AssertionError: Left and right Variable objects are not identical Differing values: L Array(1.008608e+08, dtype=float64) R array(1.008608e+08, dtype=float32) Falsifying example: test_reduce_variable( self=<xarray.tests.duckarrays.test_array_api.TestReductions object at 0x7fc1cfe85090>, method='sum', dtype_assumption=is_real_floating, data=data(...), ) Draw 1: <xarray.Variable (0: 3)> Array([33620276., 33620276., 33620276.], dtype=float32) Draw 2: ['0'] actual: <xarray.Variable ()> Array(1.00860828e+08, dtype=float64) expected: <xarray.Variable ()> array(1.0086083e+08, dtype=float32) You can reproduce this example by temporarily adding @reproduce_failure('6.92.2', b'AXicY2ZgZGQAAiYGCGBiZDQG0QABxwA/') as a decorator on your test case

Check failure on line 110 in xarray/testing/duckarrays.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.11

TestReductions.test_reduce_variable[sum-is_real_floating] AssertionError: Left and right Variable objects are not identical Differing values: L Array(16777225., dtype=float64) R array(16777224., dtype=float32) Falsifying example: test_reduce_variable( self=<xarray.tests.duckarrays.test_array_api.TestReductions object at 0x7f7662cf5c50>, method='sum', dtype_assumption=is_real_floating, data=data(...), ) Draw 1: <xarray.Variable (0: 5)> Array([3355445., 3355445., 3355445., 3355445., 3355445.], dtype=float32) Draw 2: ['0'] actual: <xarray.Variable ()> Array(16777225., dtype=float64) expected: <xarray.Variable ()> array(16777224., dtype=float32) You can reproduce this example by temporarily adding @reproduce_failure('6.92.2', b'AXicY2ZgZGQAAhYGKDA2NgVRAARrAKU=') as a decorator on your test case

Check failure on line 110 in xarray/testing/duckarrays.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.9

TestReductions.test_reduce_variable[max-is_real_floating] hypothesis.errors.FailedHealthCheck: It looks like your strategy is filtering out a lot of data. Health check found 50 filtered examples but only 9 good ones. This will make your tests much slower, and also will probably distort the data generation quite a lot. You should adapt your strategy to filter less. This can also be caused by a low max_leaves parameter in recursive() calls See https://hypothesis.readthedocs.io/en/latest/healthchecks.html for more information about this. If you want to disable just this health check, add HealthCheck.filter_too_much to the suppress_health_check settings for this test.

Check failure on line 110 in xarray/testing/duckarrays.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.9

TestReductions.test_reduce_variable[sum-is_real_floating] AssertionError: Left and right Variable objects are not identical Differing values: L Array(1.008608e+08, dtype=float64) R array(1.008608e+08, dtype=float32) Falsifying example: test_reduce_variable( self=<xarray.tests.duckarrays.test_array_api.TestReductions object at 0x7f7a2fd3b340>, method='sum', dtype_assumption=is_real_floating, data=data(...), ) Draw 1: <xarray.Variable (0: 3)> Array([33620276., 33620276., 33620276.], dtype=float32) Draw 2: ['0'] actual: <xarray.Variable ()> Array(1.00860828e+08, dtype=float64) expected: <xarray.Variable ()> array(1.0086083e+08, dtype=float32) You can reproduce this example by temporarily adding @reproduce_failure('6.92.2', b'AXicY2ZgZGQAAiYGCGBiZDQG0QABxwA/') as a decorator on your test case

Check failure on line 110 in xarray/testing/duckarrays.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.10 flaky

TestReductions.test_reduce_variable[sum-is_real_floating] AssertionError: Left and right Variable objects are not identical Differing values: L Array(16777217., dtype=float64) R array(16777216., dtype=float32) Falsifying example: test_reduce_variable( self=<xarray.tests.duckarrays.test_array_api.TestReductions object at 0x7f31cd511870>, method='sum', dtype_assumption=is_real_floating, data=data(...), ) Draw 1: <xarray.Variable (0: 2)> Array([1.6777216e+07, 1.0000000e+00], dtype=float32) Draw 2: ['0'] actual: <xarray.Variable ()> Array(16777217., dtype=float64) expected: <xarray.Variable ()> array(16777216., dtype=float32) You can reproduce this example by temporarily adding @reproduce_failure('6.92.2', b'AXicY2ZgZGQAAjABAYxwNowBAAEhAAo=') as a decorator on your test case

Check failure on line 110 in xarray/testing/duckarrays.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.9

TestReductions.test_reduce_variable[sum-is_real_floating] AssertionError: Left and right Variable objects are not identical Differing values: L Array([16777221.], dtype=float64) R array([16777220.], dtype=float32) Falsifying example: test_reduce_variable( self=<xarray.tests.duckarrays.test_array_api.TestReductions object at 0x1564f4220>, method='sum', dtype_assumption=is_real_floating, data=data(...), ) Draw 1: <xarray.Variable (0: 3, 1: 1)> Array([[5592407.], [5592407.], [5592407.]], dtype=float32) Draw 2: ['0'] actual: <xarray.Variable (1: 1)> Array([16777221.], dtype=float64) expected: <xarray.Variable (1: 1)> array([16777220.], dtype=float32) You can reproduce this example by temporarily adding @reproduce_failure('6.92.2', b'AXicY2ZgZGRgABFAiokBBkJDw0GiDAwACTEBDQ==') as a decorator on your test case

Check failure on line 110 in xarray/testing/duckarrays.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.11

TestReductions.test_reduce_variable[sum-is_real_floating] AssertionError: Left and right Variable objects are not identical Differing values: L Array(16777225., dtype=float64) R array(16777224., dtype=float32) Falsifying example: test_reduce_variable( self=<xarray.tests.duckarrays.test_array_api.TestReductions object at 0x15301e5d0>, method='sum', dtype_assumption=is_real_floating, data=data(...), ) Draw 1: <xarray.Variable (0: 5)> Array([3355445., 3355445., 3355445., 3355445., 3355445.], dtype=float32) Draw 2: ['0'] actual: <xarray.Variable ()> Array(16777225., dtype=float64) expected: <xarray.Variable ()> array(16777224., dtype=float32) You can reproduce this example by temporarily adding @reproduce_failure('6.92.2', b'AXicY2ZgZGQAAhYGKDA2NgVRAARrAKU=') as a decorator on your test case
(
"all",
"any",
("all", lambda x: True), # should work for any dtype
("any", lambda x: True), # should work for any dtype
# "cumprod", # not in array API
# "cumsum", # not in array API
# "max", # only in array API for real numeric dtypes
# "max", # only in array API for real floating point dtypes
("max", is_real_floating), # only in array API for real numeric dtypes
# "median", # not in array API
# "min", # only in array API for real numeric dtypes
# "prod", # only in array API for numeric dtypes
("min", is_real_floating), # only in array API for real numeric dtypes
("prod", is_real_floating), # only in array API for real numeric dtypes
# "std", # TypeError: std() got an unexpected keyword argument 'ddof'
# "sum", # only in array API for numeric dtypes
("sum", is_real_floating), # only in array API for real numeric dtypes
# "var", # TypeError: std() got an unexpected keyword argument 'ddof'
),
)
@given(st.data())
def test_reduce_variable(self, method, data):
def test_reduce_variable(self, method, dtype_assumption, data):
"""
Test that the reduction applied to an xarray Variable is always equal
to the same reduction applied to the underlying array.
"""

narrowed_dtypes = self.dtypes.filter(dtype_assumption)

var = data.draw(
xrst.variables(
array_strategy_fn=self.array_strategy_fn,
dims=xrst.dimension_names(min_dims=1),
dtype=self.dtypes,
dtype=narrowed_dtypes,
)
)

Expand Down

0 comments on commit d2b35c5

Please sign in to comment.