-
Notifications
You must be signed in to change notification settings - Fork 14k
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: Add quarter unit to datetrunc #17416
feat: Add quarter unit to datetrunc #17416
Conversation
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, just a comment on the week parsing.
Also... the code in the parser doesn't even look like Python. Crazy.
superset/utils/date_parser.py
Outdated
elif unit == "month": | ||
dttm = dttm.replace(day=1, hour=0, minute=0, second=0, microsecond=0) | ||
elif unit == "week": | ||
dttm = dttm - relativedelta(days=dttm.weekday()) | ||
dttm = -relativedelta(days=dttm.weekday()) |
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.
Is this intentional? Or did you mean ddtm -= relativedelta(...)
?
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.
Oops.
Codecov Report
@@ Coverage Diff @@
## master #17416 +/- ##
==========================================
- Coverage 77.01% 76.80% -0.22%
==========================================
Files 1040 1040
Lines 56077 56080 +3
Branches 7738 7738
==========================================
- Hits 43190 43072 -118
- Misses 12629 12750 +121
Partials 258 258
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
superset/utils/date_parser.py
Outdated
@@ -322,10 +323,12 @@ def eval(self) -> datetime: | |||
dttm = dttm.replace( | |||
month=1, day=1, hour=0, minute=0, second=0, microsecond=0 | |||
) | |||
if unit == "quarter": | |||
dttm = datetime(dttm.year, 3 * pd.Timestamp(dttm).quarter - 2, 1) |
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.
Try
dttm = pd.Period(pd.Timestamp(dttm), freq=FREQ_STR).to_timestamp()
I totally agree. I'm like whoa what is this. |
9ddae41
to
27a47d2
Compare
27a47d2
to
c5f3dab
Compare
Co-authored-by: John Bodley <john.bodley@airbnb.com>
This is would be a major usability improvement for my org and seems to be a small localized change. Any chance it can be included it in the next release? @villebro |
@a-cid this PR is included in the 1.5 cut, so will be included in the forthcoming 1.5.0 release once the vote passes. |
SUMMARY
It's somewhat typical to report for the current quarter (QTD) and currently the only way to do this is to define a broad time range and then add a custom SQL filter based on the current timestamp.
This request has been mentioned in a couple of Stack Overflow questions:
MTD, YTD, etc. are supported via the sweet date parse logic—kudos to whoever added this functionality—using the
datetrunc
functionality, thus I thought I should extend this to also include thequarter
unit.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TESTING INSTRUCTIONS
Added unit test.
ADDITIONAL INFORMATION