Skip to content

fix: handle IndexError on malformed format strings in parser#1280

Open
amanv0007 wants to merge 1 commit into
arrow-py:masterfrom
amanv0007:fix-parser-indexerror
Open

fix: handle IndexError on malformed format strings in parser#1280
amanv0007 wants to merge 1 commit into
arrow-py:masterfrom
amanv0007:fix-parser-indexerror

Conversation

@amanv0007
Copy link
Copy Markdown

  • Catch IndexError during token group extraction and raise ParserMatchError instead.
  • Add test case for malformed format strings lacking expected regex named groups.
  • Fixes IndexError in DateTimeParser.parse #1191

Pull Request Checklist

Thank you for taking the time to improve Arrow! Before submitting your pull request, please check all appropriate boxes:

  • 🧪 Added tests for changed code.
  • 🛠️ All tests pass when run locally (run tox or make test to find out!).
  • 🧹 All linting checks pass when run locally (run tox -e lint or make lint to find out!).
  • 📚 Updated documentation for changed code.
  • ⏩ Code is up-to-date with the master branch.

If you have any questions about your code changes or any of the points above, please submit your questions along with the pull request and we will try our best to help!

Description of Changes

- Catch IndexError during token group extraction and raise ParserMatchError instead.
- Add test case for malformed format strings lacking expected regex named groups.
- Fixes arrow-py#1191
Copilot AI review requested due to automatic review settings May 19, 2026 17:20
@codecov
Copy link
Copy Markdown

codecov Bot commented May 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (2224255) to head (b3bee71).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #1280   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           10        10           
  Lines         2315      2318    +3     
  Branches       358       358           
=========================================
+ Hits          2315      2318    +3     

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

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens arrow.parser.DateTimeParser.parse() against malformed format strings that previously could trigger an uncaught IndexError during regex match-group extraction, converting that failure mode into a ParserMatchError and adding a regression test for the reported crash.

Changes:

  • Wrap match-group extraction in DateTimeParser.parse() with an IndexError handler that raises ParserMatchError.
  • Add a regression test asserting malformed format strings raise ParserMatchError instead of IndexError.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
arrow/parser.py Catches IndexError from match.group(...) during token extraction and re-raises ParserMatchError.
tests/test_parser.py Adds a regression test covering the malformed-format-string crash scenario.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread arrow/parser.py
Comment on lines +434 to +435
f"Failed to match {fmt!r} when parsing {datetime_string!r}."
)
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.

IndexError in DateTimeParser.parse

2 participants