data-apis / array-api-tests

Test suite for the PyData Array APIs standard
https://data-apis.org/array-api-tests/
MIT License
64 stars 41 forks source link

Clean up the data in test_type_promotion.py #21

Closed asmeurer closed 3 years ago

asmeurer commented 3 years ago

Everything that's not a test in test_type_promotion.py is a mess right now. There are tons of data dictionaries and helper functions. Quite a few of them are needed throughout the test suite, so they should be moved to a more central location. Furthermore, the data has a lot of redundancies, and even so, to use it, you often have to do tons of dict lookups to get at what you want. I think the biggest problem here is that I used the string values of the dtypes as the main key in the dictionaries, meaning you always have to translate those to actual dtype objects to use them. We should just use the actual dtype objects instead. The only concern here is that the dtype objects might not be hashable. But I don't think this is an actual problem in practice. If it somehow does become a problem for some library, we can worry about it then, and whether it should be worked around in the suite or if we should just require hashability in the spec (we already require equality). Finally, the parameterization logic for the tests that are in test_type_promotion is a bunch of hard to read list comprehensions. They may become easier to read once we refactor the data. If not, we should clean them up as well. So to summarize

honno commented 3 years ago

Working on this, thanks for the checklist. Will let you know if I have any questions.

honno commented 3 years ago

RE hashability, worst case there's probably a hack we can do in _array_module to wrap dtypes in hashable items (i.e. use dtype string names as hashes). This might be useful anyway so we can get consistent str(dtype) output for things like error messages and pytest parameters.

asmeurer commented 3 years ago

That would mean we'd have to unpack the dtype object everywhere it is used, though. Let's not worry about this unless/until it becomes an issue for some actual library. I doubt any of the existing libraries have unhashable dtypes.