Skip to content

BUG: validate to_offset aliases before stride parsing#65587

Open
sun-0-set wants to merge 3 commits into
pandas-dev:mainfrom
sun-0-set:codex/fix-to-offset-invalid-alias
Open

BUG: validate to_offset aliases before stride parsing#65587
sun-0-set wants to merge 3 commits into
pandas-dev:mainfrom
sun-0-set:codex/fix-to-offset-invalid-alias

Conversation

@sun-0-set
Copy link
Copy Markdown

@sun-0-set sun-0-set commented May 11, 2026

When parsing fractional strides with an invalid non-tick alias, to_offset attempts to parse the stride as an integer before validating the alias, exposing a lower-level invalid literal for int() error for inputs like "2.5foo", which obfuscates the actual error (invalid alias).

This runs offset=_get_offset() early to validate non-tick offset names before going into stride parsing.

Note: This is not elegant in the least, but imo does the job. A broader fix would entail rethinking the validation and error reporting logic for invalid and deprecated aliases/suffixes.

Validation: python -m pytest pandas/tests/tslibs/test_to_offset.py -q

@jbrockmendel
Copy link
Copy Markdown
Member

cc @natmokval

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.

2 participants