Repository navigation
feat: Repr prints exactly what NumPy 2.5.3's repr prints - #49
Merged
Merged
Conversation
Repr wrote each element in its shortest form and right-aligned them, so its digits and padding differed from NumPy's: array([1.5, 2., 3.]) where NumPy prints array([1.5, 2. , 3. ]), 1e+20 where it prints 1.e+20, " True" missing its space when no False is present, and no scientific notation for arange(2000.). display.go is now a port of numpy/_core/arrayprint.py at v2.5.3 (FloatingFormat in maxprec mode, precision 8; ComplexFloatingFormat; IntegerFormat; BoolFormat; _formatArray and _extendLine; the repr's shape=/dtype= extras and their wrapping), with dragon4.c's digits: the shortest that read back, cut to 8 and rounded half to even on the exact value, which is how strconv rounds. The scientific cut-off depends on the dtype as in 2.5.3: 1e8 for float64, 1e6 for float32. Checked against NumPy's own expected strings (test_arrayprint.py, v2.5.3): 26 repr cases, the 72 complex special values of TestComplexArray.test_str, and gh-28679's float32/complex64 cut-off elements. Breaking the float32 cut-off or the bool padding fails them. Three old expectations encoded the previous, wrong output; corrected. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Reprwrote each element in its shortest form and right-aligned them, so its digits and padding differed from NumPy's:[1.5, 2, 3]float32array([1.5, 2., 3.], dtype=float32)array([1.5, 2. , 3. ], dtype=float32)[1e20, 0.5]array([1e+20, 0.5])array([1.e+20, 5.e-01])[True, True]array([True, True])array([ True, True])arange(2000.)array([ 0., 1., …array([0.000e+00, 1.000e+00, …(max/min > 1000)display.gois now a port ofnumpy/_core/arrayprint.pyat v2.5.3:FloatingFormat(maxprec, precision 8),ComplexFloatingFormat,IntegerFormatandBoolFormat._formatArrayand_extendLinewith 75 columns.shape=anddtype=extras, including their wrapping onto a new line.dragon4.c: the shortest that read back, cut to 8 and rounded half to even on the exact value. That is also howstrconvrounds.Oracle. NumPy's own expected strings, copied verbatim from
test_arrayprint.py(v2.5.3):reprcases, from test_nan_inf, test_float_spacing, test_bool_spacing, test_sign_spacing, test_floatmode (maxprec), test_summarize_1d/2d and test_summarize_2d_dtype;TestComplexArray.test_str, complex64 and complex128);Four more cases have no default-options case in NumPy's suite (empty arrays, the 8-digit cut in scientific mode, a negative tiny value). For those, the expectation is derived from the rules, and the rule is written beside each case.
Checks:
Downstream: go-embedded-ruby's
NDArray#inspectprints thisRepr. Its tests that compare against go-ndarray computed in Go will follow on their own. Literal strings in its tests will need the NumPy forms when it moves to this release.🤖 Generated with Claude Code