Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enh: adding automated inferencing of format %Y-%m-%dT%H:%M in pyarrow #1292

Merged
merged 5 commits into from
Nov 1, 2024

Conversation

raisadz
Copy link
Contributor

@raisadz raisadz commented Oct 31, 2024

What type of PR is this? (check all applicable)

  • πŸ’Ύ Refactor
  • ✨ Feature
  • πŸ› Bug Fix
  • πŸ”§ Optimization
  • πŸ“ Documentation
  • βœ… Test
  • 🐳 Other

Related issues

Checklist

  • Code follows style guide (ruff)
  • Tests added
  • Documented the changes

If you have comments or can explain your changes, please do so below.

@github-actions github-actions bot added the enhancement New feature or request label Oct 31, 2024
@MarcoGorelli
Copy link
Member

awesome!

@FBruzzesi fancy taking a look if you have time? (not urgent of course)

@raisadz raisadz marked this pull request as ready for review October 31, 2024 12:45
Copy link
Member

@FBruzzesi FBruzzesi left a comment

Choose a reason for hiding this comment

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

Thanks a ton @raisadz πŸ™ŒπŸΌ

It already looks good, yet I left a couple of opinionated comments πŸ™ˆ

Let me know what you think

narwhals/_arrow/utils.py Outdated Show resolved Hide resolved
Comment on lines 423 to 431
format = ""
matches = pc.extract_regex(arr, pattern=HMS_RE)
if pc.all(matches.is_valid()).as_py():
format = "%H:%M:%S"
else:
matches = pc.extract_regex(arr, pattern=HM_RE)
if pc.all(matches.is_valid()).as_py():
format = "%H:%M"
return format
Copy link
Member

Choose a reason for hiding this comment

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

Opinionated take is to follow a similar pattern (pun unintended) as per date regex, i.e. having a format mapping:

TIME_FORMATS = (
    (HMS_RE, "%H:%M:%S"),
    (HM_RE, "%H:%M"),
)

and here loop through that and have a early return for the first that fully matches, otherwise return empty string

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the suggestion @FBruzzesi! I added a time formatting mapping similar to how it is done for dates, it looks much nicer now πŸŽ‰

Copy link
Member

@FBruzzesi FBruzzesi left a comment

Choose a reason for hiding this comment

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

Love it! Thank you so much πŸš€

NarwhalChubbiwhalGIF

@FBruzzesi FBruzzesi merged commit 6b5e2bf into narwhals-dev:main Nov 1, 2024
22 checks passed
@raisadz raisadz deleted the pyarrow-date-parsing branch November 7, 2024 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants