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

feat: custom datetime formatting in .fmt_datetime() #645

Merged
merged 7 commits into from
Mar 24, 2025

Conversation

rich-iannone
Copy link
Member

@rich-iannone rich-iannone commented Mar 21, 2025

This adds the format_str= parameter to the .fmt_datetime() so that users can use any strftime formatting string. Added tests to ensure that this works for both date and datetime inputs.

Fixes: #639

Copy link

codecov bot commented Mar 21, 2025

Codecov Report

Attention: Patch coverage is 88.88889% with 1 line in your changes missing coverage. Please review.

Project coverage is 91.17%. Comparing base (6779205) to head (91cf6d8).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
great_tables/_formats.py 88.88% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #645      +/-   ##
==========================================
- Coverage   91.19%   91.17%   -0.02%     
==========================================
  Files          47       47              
  Lines        5460     5464       +4     
==========================================
+ Hits         4979     4982       +3     
- Misses        481      482       +1     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions github-actions bot temporarily deployed to pr-645 March 21, 2025 16:43 Destroyed
@rich-iannone rich-iannone marked this pull request as ready for review March 21, 2025 17:05
@rich-iannone rich-iannone requested a review from machow as a code owner March 21, 2025 17:05
if format_str is not None:
# If `x` is a string, assume it is an ISO datetime string and convert
# it to a datetime object
if isinstance(x, str):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you pull this above the block, so it applies to the if and else case? (and then remove the redundant version on 2239 in the else)


else:
# Stop if `x` is not a valid datetime object
_validate_datetime_obj(x=x)
Copy link
Collaborator

Choose a reason for hiding this comment

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

AFAICT this if / else should just stay the same, and the extra formatting logic should go below it

@github-actions github-actions bot temporarily deployed to pr-645 March 24, 2025 17:41 Destroyed
@github-actions github-actions bot temporarily deployed to pr-645 March 24, 2025 17:42 Destroyed
Copy link
Collaborator

@machow machow left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@rich-iannone rich-iannone self-assigned this Mar 24, 2025
@rich-iannone rich-iannone merged commit e4e1ec4 into main Mar 24, 2025
13 of 14 checks passed
@rich-iannone rich-iannone deleted the feat-custom-datetime-formatting branch March 24, 2025 19:26
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.

Allow custom datetime formats
2 participants