-
Notifications
You must be signed in to change notification settings - Fork 86
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
Conversation
Codecov ReportAttention: Patch coverage is
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. 🚀 New features to boost your workflow:
|
great_tables/_formats.py
Outdated
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): |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
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