Repository navigation
Fix table indices serialization test failures on ARMv7 and improve coverage - #19644
Conversation
|
Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.
|
neutrinoceros
left a comment
There was a problem hiding this comment.
cool ! while we're at it, we should also cover cases with mixed dtypes, otherwise LGTM. Thank you
| from .test_table import SetupData | ||
|
|
||
| available_engines = [BST, SortedArray] | ||
| NATIVE_INT_NAME = np.array(0).dtype.name |
There was a problem hiding this comment.
a slightly more straightforward form of this
| NATIVE_INT_NAME = np.array(0).dtype.name | |
| NATIVE_INT_NAME = np.int_.__name__ |
There was a problem hiding this comment.
np.int is deprecated since numpy 1.20. There is a reason I did it the original way.
Sorry, I missed the trailing _.
There was a problem hiding this comment.
The suggestion was np.int_, which is not deprecated, but I personally prefer the np.array(0) route as just letting the data do the work.
There was a problem hiding this comment.
While checking for a sign of deprecation (and indeed, there is none), I also realized that I incorrectly recalled np.int_ to represent the native integer type when it's actually just always equivalent to np.int64. Which means I don't know why it even exists. Live and learn.
| @pytest.mark.parametrize("dtype", [np.int16, np.float32, np.int64, np.float64]) | ||
| def test_indices_roundtrip_various_dtypes(dtype): | ||
| """Test that serialization round-trip works for various index dtypes.""" | ||
| t = Table() | ||
| t["a"] = np.array([1, 3, 2], dtype=dtype) | ||
| t["b"] = np.array([5, 6, 7], dtype=dtype) |
There was a problem hiding this comment.
also making sure we roundtrip tables with mixed dtypes correctly
| @pytest.mark.parametrize("dtype", [np.int16, np.float32, np.int64, np.float64]) | |
| def test_indices_roundtrip_various_dtypes(dtype): | |
| """Test that serialization round-trip works for various index dtypes.""" | |
| t = Table() | |
| t["a"] = np.array([1, 3, 2], dtype=dtype) | |
| t["b"] = np.array([5, 6, 7], dtype=dtype) | |
| DTYPES = [np.int16, np.int32, np.int64, np.float32, np.float64] | |
| @pytest.mark.parametrize("dt1", DTYPES) | |
| @pytest.mark.parametrize("dt2", DTYPES) | |
| def test_indices_roundtrip_various_dtypes(dt1, dt2): | |
| """Test that serialization round-trip works for various index dtypes.""" | |
| t = Table() | |
| t["a"] = np.array([1, 3, 2], dtype=dt1) | |
| t["b"] = np.array([5, 6, 7], dtype=dt2) |
There was a problem hiding this comment.
This is only a waste of CPU and time. The output indices that are being serialized are always native int and they do not depend on the data type. Even my original test is not strictly telling us much, but at least it is only 4 types, instead you're suggestion is for 25. Tests need to provide demonstrable value since they are not free.
# %ECSV 1.0
# ---
# datatype:
# - {name: a, datatype: int16} <-- This is tested thoroughly elsewhere
# - {name: b, datatype: float32}
# - {name: __index__, datatype: int64} <-- Doesn't depend on input datatype
# - {name: __index__1, datatype: int64}
# meta: !!omap
# - __table_indices__:
# indices:
# - colnames: [a]
# index_colname: __index__
# - colnames: [a, b]
# index_colname: __index__1
# primary_key: [a]
# schema: astropy-2.0
a b __index__ __index__1
1 5.0 0 0
3 6.0 2 2
2 7.0 1 1
There was a problem hiding this comment.
I agree that we should not go overboard with testing, if only to save some energy costs (aside: this is partially why I like so much the idea of moving the compiled code out of astropy).
| 2 3 2 | ||
| 3 5 0 | ||
| 1 4 1 | ||
| See the ``test_indices_serialization_*` tests in ``test_index.py`` for examples. |
There was a problem hiding this comment.
I'm not sure there's a precedent for referencing tests directly in a docstring. This doesn't seem right to me: it would bitrot silently if we were to remove tests from wheels, for instance (not likely to happen soon, but not an impossibility on the long term). I suggest using the patch from #19634 here instead.
There was a problem hiding this comment.
For all intents and purposes this is an internal function that only developers will be checking. You are going to say it should be explicit with _ but that's just not the way this code has been developed over 15 years. This level of fear about inconsequential changes that have both low impact and low probability is not warranted.
There was a problem hiding this comment.
The example here was helpful, but I can see the case for feeling that having to make it work for different architectures is beyond what is reasonable for a helper function. I do like having a little hint where to look here, and our tests have historically been pretty much invariant, so this seems fine to me.
mhvk
left a comment
There was a problem hiding this comment.
@taldcroft - arrgg, 32 bit integers again come back to haunt us! Your solution here looks good to me.
| from .test_table import SetupData | ||
|
|
||
| available_engines = [BST, SortedArray] | ||
| NATIVE_INT_NAME = np.array(0).dtype.name |
There was a problem hiding this comment.
The suggestion was np.int_, which is not deprecated, but I personally prefer the np.array(0) route as just letting the data do the work.
| @pytest.mark.parametrize("dtype", [np.int16, np.float32, np.int64, np.float64]) | ||
| def test_indices_roundtrip_various_dtypes(dtype): | ||
| """Test that serialization round-trip works for various index dtypes.""" | ||
| t = Table() | ||
| t["a"] = np.array([1, 3, 2], dtype=dtype) | ||
| t["b"] = np.array([5, 6, 7], dtype=dtype) |
There was a problem hiding this comment.
I agree that we should not go overboard with testing, if only to save some energy costs (aside: this is partially why I like so much the idea of moving the compiled code out of astropy).
| 2 3 2 | ||
| 3 5 0 | ||
| 1 4 1 | ||
| See the ``test_indices_serialization_*` tests in ``test_index.py`` for examples. |
There was a problem hiding this comment.
The example here was helpful, but I can see the case for feeling that having to make it work for different architectures is beyond what is reasonable for a helper function. I do like having a little hint where to look here, and our tests have historically been pretty much invariant, so this seems fine to me.
|
It doesn't look like any of my suggestions, comments and questions have produced anything other than frustration for all parties involved. If small improvements and a critical perspective on 15 years old practices are both deemed undesirable, then I do not know what to offer as a reviewer. |
@neutrinoceros requested his review be dismissed
Description
This pull request is to address fix test failures from #18703 on platforms like ARMv7 where
int64is not the native integer type. It also expands test coverage to include creating indices with a variety of dtypes to stress the system a bit more.Fixes #19632