codeant-ai-for-open-source[bot] commented on code in PR #42678:
URL: https://github.com/apache/superset/pull/42678#discussion_r3701136814
##########
superset/utils/pandas_postprocessing/resample.py:
##########
@@ -47,7 +55,18 @@ def resample(
)
if method == "asfreq" and fill_value is not None:
- _df = df.resample(rule).asfreq(fill_value=fill_value)
+ origin = time_range_start if time_range_start is not None else
"start_day"
+ _df = df.resample(rule, origin=origin).asfreq(fill_value=fill_value)
+ if time_range_start is not None and time_range_end is not None:
+ # Zero-filling should cover the entire queried time range, not
+ # just the span between the first and last existing data points.
+ full_index = pd.date_range(
+ start=time_range_start,
+ end=time_range_end,
+ freq=rule,
+ inclusive="left",
+ )
+ _df = _df.reindex(full_index, fill_value=fill_value)
Review Comment:
**Suggestion:** `pd.date_range` does not necessarily produce the same labels
as `df.resample(rule)`, especially for calendar rules such as month-start,
quarter-start, or year-start frequencies. With a query starting mid-month, a
month-start resampler can produce the bucket labeled at the start of that month
while `date_range(start=time_range_start, freq=rule)` starts at the next month;
`reindex` then discards the real bucket and replaces it with zero-filled
labels. Build the full index from the resampler's actual bucket alignment
rather than independently generating it from the raw query start. [incorrect
condition logic]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ❌ Month-start zero-fill charts can lose first-period data.
- ⚠️ Calendar-based resampling labels differ from query results.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=efb8384d8e5b490489a03383e2aaa3b5&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=efb8384d8e5b490489a03383e2aaa3b5&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset/utils/pandas_postprocessing/resample.py
**Line:** 63:69
**Comment:**
*Incorrect Condition Logic: `pd.date_range` does not necessarily
produce the same labels as `df.resample(rule)`, especially for calendar rules
such as month-start, quarter-start, or year-start frequencies. With a query
starting mid-month, a month-start resampler can produce the bucket labeled at
the start of that month while `date_range(start=time_range_start, freq=rule)`
starts at the next month; `reindex` then discards the real bucket and replaces
it with zero-filled labels. Build the full index from the resampler's actual
bucket alignment rather than independently generating it from the raw query
start.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42678&comment_hash=293dae44a939268013662769a1fe0db66978219309c8b40c7626770b12a6e7f4&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42678&comment_hash=293dae44a939268013662769a1fe0db66978219309c8b40c7626770b12a6e7f4&reaction=dislike'>👎</a>
##########
superset/utils/pandas_postprocessing/resample.py:
##########
@@ -47,7 +55,18 @@ def resample(
)
if method == "asfreq" and fill_value is not None:
- _df = df.resample(rule).asfreq(fill_value=fill_value)
+ origin = time_range_start if time_range_start is not None else
"start_day"
+ _df = df.resample(rule, origin=origin).asfreq(fill_value=fill_value)
Review Comment:
**Suggestion:** Passing an aware query bound as `origin` to a resampler
whose `DatetimeIndex` is naive, or vice versa, raises a pandas
timezone-compatibility error. Query boundaries are commonly UTC-aware while
database result indexes are not guaranteed to have timezone metadata. Normalize
both bounds and the DataFrame index to compatible timezone awareness before
resampling. [type error]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ❌ Timeseries queries with timezone offsets can return validation errors.
- ⚠️ Zero-fill post-processing becomes dependent on index timezone metadata.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=6e4bf68555ef4ec29724605b5f0aa466&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=6e4bf68555ef4ec29724605b5f0aa466&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset/utils/pandas_postprocessing/resample.py
**Line:** 58:59
**Comment:**
*Type Error: Passing an aware query bound as `origin` to a resampler
whose `DatetimeIndex` is naive, or vice versa, raises a pandas
timezone-compatibility error. Query boundaries are commonly UTC-aware while
database result indexes are not guaranteed to have timezone metadata. Normalize
both bounds and the DataFrame index to compatible timezone awareness before
resampling.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42678&comment_hash=b8902a57f93556174e4cef6df5987fb013165c026ccd27dc1046a78fa9eaff1a&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42678&comment_hash=b8902a57f93556174e4cef6df5987fb013165c026ccd27dc1046a78fa9eaff1a&reaction=dislike'>👎</a>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]