Skip to content

fix: preserve NumPy datetime formatting (issue #251) - #474

Open
chiragjangiir wants to merge 1 commit into
astanin:masterfrom
chiragjangiir:fix/issue-251-numpy-datetime64-formatting
Open

chiragjangiir wants to merge 1 commit into
astanin:masterfrom
chiragjangiir:fix/issue-251-numpy-datetime64-formatting

Conversation

@chiragjangiir

Copy link
Copy Markdown

Summary

Fixes #251 by preventing NumPy datetime and timedelta values from being incorrectly classified as numeric values during table formatting.

Problem

NumPy nanosecond-resolution timestamps can be converted to floats. This causes values such as np.datetime64("2022-10-05", "ns") to be rendered as scientific notation (for example, 1.66493e+18) instead of as readable datetime strings.

Implementation

  • Exclude NumPy datetime and timedelta scalars from numeric detection.
  • Handle zero-dimensional temporal arrays using dtype.kind.
  • Avoid adding a mandatory NumPy import.
  • Preserve numeric formatting for ordinary numeric values and supported types such as Decimal and Fraction.

Regression coverage

Tests cover:

  • Nanosecond datetime scalars.
  • Zero-dimensional and two-dimensional NumPy arrays.
  • Other datetime resolutions.
  • Mixed datetime and numeric tables.
  • Numeric alignment and existing numeric types.

Tests

  • Full test suite: 333 passed, 51 skipped.
  • git diff --check: passed.
    These tests were run locally before publication.

Related work

This change addresses the maintainer's previously stated request for regression coverage on the existing issue. PR #252 is related; this PR provides additional edge-case coverage. The maintainer can decide how best to consolidate the contributions.

Exclude NumPy datetime and timedelta values from numeric detection
so nanosecond timestamps and zero-dimensional temporal arrays are
rendered as text rather than scientific-notation floats.

Add regression coverage for scalar and array inputs, multiple
datetime resolutions, and mixed numeric tables.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

numpy.datetime64[ns] is wrongly formatted as float

1 participant