GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Cubed xarray tests by TomNicholas · Pull Request #4 · xarray-contrib/xarray-array-testing

Conversation

@TomNicholas

@TomNicholas TomNicholas commented Aug 22, 2024

Copy link
Copy Markdown
Member

No description provided.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
TomNicholas and others added 3 commits August 22, 2024 17:01
@TomNicholas
add tests for cubed
1532ec8
@TomNicholas
silence hypothesis health check warnings
9be6e3c
@pre-commit-ci
[pre-commit.ci] auto fixes from pre-commit.com hooks
df26fc7
for more information, see https://pre-commit.ci
@TomNicholas TomNicholas mentioned this pull request Aug 22, 2024
Design of an inherited xarray duck array test suite #6
Open
@dcherian

dcherian commented Aug 22, 2024

Copy link
Copy Markdown

If its useful, I wrote a chunks strategy here:
https://github.com/xarray-contrib/flox/blob/edc13445a098ee95f074a4bd92bde1c48694804c/tests/strategies.py#L115-L127

though it does generate non-uniform chunks

TomNicholas reacted with eyes emoji
All reactions
  • 👀 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@TomNicholas

TomNicholas commented Aug 22, 2024

Copy link
Copy Markdown
Member Author

I wrote a chunks strategy here:

@dcherian I also wrote one at dask/dask#9374 😆

It will be useful eventually, but right now we're trying to get the testing framework in place that the chunk strategy would plug into. The chunk-generating strategy would be called by the cubed_random_array strategy.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

TomNicholas
TomNicholas commented Aug 22, 2024
View reviewed changes
Comment thread xarray_array_testing/creation.py


class CreationTests(DuckArrayTestMixin):
@settings(suppress_health_check=[HealthCheck.differing_executors])

@TomNicholas TomNicholas Aug 22, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Zac-HD the fact we had to add this seems to indicate a possibly-serious misuse of hypothesis, but in some way that @keewis and I struggled to properly understand from looking at the docs.

https://hypothesis.readthedocs.io/en/latest/settings.html#hypothesis.HealthCheck.differing_executors

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@Zac-HD Zac-HD Aug 22, 2024

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see HypothesisWorks/hypothesis#3446 for the motivating cases; if you inherit an @given() test onto multiple child classes with different behavior you can get some pretty weird behaviors.

If you don't observe anything like that, it's probably okay albeit fragile.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@TomNicholas TomNicholas Aug 22, 2024

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the very limited running we did today, we didn't observe anything unexpected after we disabled the health check.

But is there some other pattern we should be using here?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@Zac-HD Zac-HD Aug 23, 2024

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have any concrete suggestions; inheritance for code-sharing is both useful in this kind of situation, and also prone to sharing slightly more state than we want it to. A design that doesn't use inheritance would be safer but I'm not sure it's worth the trouble.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

TomNicholas reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@TomNicholas TomNicholas Aug 23, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay thanks. Sounds like perhaps we should disable this warning globally (if possible) and just report if it actually causes problems.

if you inherit an @given() test onto multiple child classes with different behavior

We are not actually ever going to be inheriting one given test onto multiple child classes, only onto one child class (per downstream package). So maybe that makes it okay?

...actually the one exception to that statement would be in Xarray itself, where we would inherit once to test wrapping numpy, once to test wrapping dask etc. But we could probably still set up our CI to ensure that only one child test class (suite of children really) gets run per CI job.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Zac-HD reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@Zac-HD Zac-HD Aug 23, 2024

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fine, iirc it's only an issue if you're replaying test cases from the database and the underlying sequence of choices is different and you hit a particular unlucky situation.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

TomNicholas reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@keewis keewis Aug 23, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually the one exception to that statement would be in Xarray itself

not only that, unfortunately: if you want to check how dask and cupy work together, for example, cupy-xarray would have to create both the suite for cupy and the dask+cupy one.

The other option we'd have is to generate a single test class within a function:

def generate_tests(name, array_strategy, array_type, xp):
    @rename_class(f"Test{name.title().replace('_', '')}Array")
    class TestDuckArray:
        class TestCreation:
            array_strategy_fn = array_strategy
            ...

    return TestDuckArray

TestNumpyArray = generate_tests("numpy", create_numpy_array, np.ndarray, np)

which would avoid the reuse of a single given, but this quickly becomes tricky to read because of the deeply nested structure.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@keewis keewis Aug 23, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried to work around this in #7 by delaying the application of given.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@TomNicholas TomNicholas Aug 23, 2024

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whilst #7 is clever I think my conclusion from @Zac-HD 's comments above is that the extra complexity is unnecessary - it's fine to just suppress the warning and we only need to revisit this issue if we ever actually observe weird behaviour (i.e. YAGNI).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Zac-HD reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Zac-HD
Zac-HD reviewed Aug 22, 2024
View reviewed changes
Comment thread xarray_array_testing/tests/test_cubed.py
Comment on lines +23 to +24
# TODO hypothesis doesn't like us using random inside strategies
rng = np.random.default_rng()

@Zac-HD Zac-HD Aug 22, 2024

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using a Hypothesis-provided seed? I'd also be happy to accept a PR to generate Numpy prng instances 🙂

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@keewis keewis Aug 23, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probably try using xps.arrays() instead (though I guess that only works for array API compliant duck arrays)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@Zac-HD Zac-HD Aug 23, 2024

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other argument against is that sometimes you just want a faster PRNG for the elements; the distribution is a bit less likely to find bugs but setting elements individually is a lot slower (even though we do a sparse subset)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

keewis reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@keewis
install cubed and cubed-xarray in ci
72fd4bf
@keewis keewis mentioned this pull request Aug 23, 2024
use decorators to delay the application of given #7
Draft
1 task done
keewis added 8 commits August 28, 2024 11:33
@keewis
Merge branch 'main' into cubed_xarray_tests
7f2654b
@keewis
actually pass in the right op
376181c
@keewis
create a more informative error message
4610b30
@keewis
use the proper import for ContextManager
77f08c8
@keewis
simplify the dtype check
6d77f30
@keewis
skip var and std
3b16694
@keewis
expect an error for float16
f97633d
That dtype is currently not part of the spec.
@keewis
change the target version to 3.11
3e66118
@keewis

keewis commented Aug 28, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

there's two distinct failures here:

  1. mean does not support complex dtypes (complex64, complex128) which are both part of the array API. I've marked that as an expected failure for now.
  2. The reductions somehow run eagerly instead of lazily. (Even assuming that eager computation is okay, the reductions should return numpy.ndarray, but on numpy>=2.1 they return numpy scalars; this is a known bug upstream in xarray)
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@keewis

keewis commented Sep 2, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

@tomwhite, I just tried to get xarray to allow you to define __array_function__ on cubed. This was surprisingly simple, I just had to:

  1. switch the order of the checks for __array_namespace__ and __array_function__ (as described in Missing array-api support for some stats functions? pydata/xarray#8834 (comment))
  2. re-apply the PR you had reverted on cubed
  3. define nanprod on cubed
  4. remove out=out in xarray's dispatch to nanprod (which we should do anyways, considering that that's the only time xarray is actually passing through out).

with those four changes, xarray's test suite still passes in my environment, and the tests here don't fail because cubed has been eagerly computed. However, there's some floating point issues we still have to resolve (mostly floating-point errors for float32 / complex64).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tomwhite

tomwhite commented Sep 2, 2024

Copy link
Copy Markdown

@keewis awesome!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@keewis keewis keewis left review comments
+1 more reviewer
@Zac-HD Zac-HD Zac-HD left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@TomNicholas @dcherian @keewis @tomwhite @Zac-HD
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.