Skip to content

is_timestamp: reject NaN and ±inf so callers fail with a clear ValueError - #1324

Open
HrachShah wants to merge 3 commits into
arrow-py:masterfrom
HrachShah:fix/is-timestamp-reject-non-finite
Open

is_timestamp: reject NaN and ±inf so callers fail with a clear ValueError#1324
HrachShah wants to merge 3 commits into
arrow-py:masterfrom
HrachShah:fix/is-timestamp-reject-non-finite

Conversation

@HrachShah

Copy link
Copy Markdown

Replaces the 'parse as float and accept' check in is_timestamp with one that also requires the parsed value to be finite. float('nan'), float('inf'), and float('-inf') all parse cleanly today and pass is_timestamp, so Arrow.fromtimestamp then raises a generic ValueError for NaN/inf or an OverflowError for -inf — neither names the actual problem ("this is not a timestamp"). Arrow.fromtimestamp(0.0 / 0.0) etc. should surface as ValueError("The provided timestamp NaN is invalid.") at the call site, not as a confusing overflow error from inside the stdlib.

Zo Bot added 3 commits July 11, 2026 17:32
…on-zero digits

The 'S' token rounds a sub-second value to the nearest 6-digit
microsecond, but the half-way case was unconditionally applying
round-half-to-even (banker's rounding) based purely on the 6th digit.
That ignored anything after the 7th digit, so a value like
.7891235001 lost the trailing '001' and was rounded down to .789123
even though the true value sits above the half-way point and should
round up to .789124.

Restrict the banker's-rounding branch to the case where the 7th digit
is exactly 5 and all following digits are zero. When non-zero digits
follow, the truncated 6-digit value is strictly greater than the
midpoint between two adjacent microseconds, so round up regardless of
the parity of the 6th digit.

Updated test_parse_subsecond_rounding and test_gnu_date which had
pinned the old behaviour, and added test_YYYY_MM_DDTHH_mm_ss_S_round_half_up
covering the banker's / strict half-up / strictly-above / strictly-below
corners.
_Build_datetime called datetime.strptime with the G/V/u format string for
ISO 8601 weekdates, but a year like 2024 has no week 53 (only 2020, 2026,
and a handful of long-ISO years do). The bare strptime raised a ValueError
that escaped through DateTimeParser.parse and parse_iso, so a user passing
'2024-W53-1' saw a bare ValueError('Invalid week: 53') with no context
about which year/week string they had typed, instead of a ParserError
naming the offending input.
@codecov

codecov Bot commented Jul 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.91%. Comparing base (2224255) to head (6455124).

Additional details and impacted files
@@             Coverage Diff             @@
##            master    #1324      +/-   ##
===========================================
- Coverage   100.00%   99.91%   -0.09%     
===========================================
  Files           10       10              
  Lines         2315     2321       +6     
  Branches       358      347      -11     
===========================================
+ Hits          2315     2319       +4     
- Misses           0        2       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

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.

1 participant