Skip to content

Fix _TIMESTAMP_RE to match single-digit timestamps#1248

Open
bysiber wants to merge 1 commit intoarrow-py:masterfrom
bysiber:fix/timestamp-regex-single-digit
Open

Fix _TIMESTAMP_RE to match single-digit timestamps#1248
bysiber wants to merge 1 commit intoarrow-py:masterfrom
bysiber:fix/timestamp-regex-single-digit

Conversation

@bysiber
Copy link

@bysiber bysiber commented Feb 20, 2026

Summary

Fix _TIMESTAMP_RE to correctly match single-digit timestamps like epoch 0.

Problem

The current regex pattern is:

_TIMESTAMP_RE = re.compile(r"^\-?\d+\.?\d+$")

This requires \d+ (one or more digits) on both sides of the optional decimal point. For single-digit values:

  1. \d+ greedily matches the only digit
  2. \.? optionally matches nothing
  3. \d+ requires at least one more digit, but input is exhausted → no match
import re pattern = re.compile(r"^\-?\d+\.?\d+$") pattern.match("0") # None ← should match pattern.match("1") # None ← should match pattern.match("-1") # None ← should match pattern.match("10") # Match ← works for 2+ digits

This means arrow.get("0", "X") raises ParserMatchError instead of parsing epoch 0.

Fix

Change the trailing \d+ to \d* so the fractional part is fully optional:

_TIMESTAMP_RE = re.compile(r"^\-?\d+\.?\d*$")
The regex \d+\.?\d+ requires at least one digit on each side of the optional decimal point. For single-digit values like "0" or "1", the first \d+ consumes the only digit and the second \d+ fails to match anything. Change the trailing \d+ to \d* so the decimal part is fully optional, allowing single-digit timestamps like epoch 0 to be parsed with the X format token.
@bysiber bysiber force-pushed the fix/timestamp-regex-single-digit branch from 9d4a22f to 5172a88 Compare February 20, 2026 06:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant