aminghadersohi commented on code in PR #45671:
URL: https://github.com/apache/superset/pull/45671#discussion_r4428537655


##########
superset/models/helpers.py:
##########
@@ -3409,12 +3414,18 @@ def get_offset_custom_or_inherit(
             # the range against itself, and a 36-hour range would shift by a
             # single day and overlap it. Whole-day ranges resolve to the same
             # instant either way.
-            duration = outer_to_dttm - outer_from_dttm
+            from_comparison, to_comparison = get_comparable_bounds(
+                outer_from_dttm, outer_to_dttm
+            )
+            duration = to_comparison - from_comparison

Review Comment:
   For `DATETRUNC(DATETIME('2024-05-31T12:00:00+08:00'), QUARTER) : 
2024-07-01`, `inherit` shifts by the 91-day wall-clock length but the SQL 
window spans 91d 8h, so the comparison ends at 04-01 00:00 while the main 
period starts at 03-31 16:00 UTC: 8h of rows land in both (6h with 
Europe/Berlin).



##########
superset/common/query_object.py:
##########
@@ -782,11 +785,56 @@ def exec_post_processing(self, df: DataFrame) -> 
DataFrame:
                     func = extra_ops[operation]
                 options = post_process.get("options", {})
                 if operation == "resample":
-                    options = self._resolve_resample_options(options)
+                    options = self._resolve_resample_options(options, df)
                 df = func(df, **options)
             return df
 
-    def _resolve_resample_options(self, options: dict[str, Any]) -> dict[str, 
Any]:
+    def _is_resample_calendar_column(self) -> bool:
+        """Resolve physical temporal metadata for legacy and base-axis 
charts."""
+        if self.datasource is None:
+            return False
+        names = [self.granularity or get_x_axis_label(self.columns)]
+        if not self.granularity:
+            names.extend(
+                col.get("sqlExpression")
+                for col in get_base_axis_columns(self.columns)[:1]
+                if isinstance(col, dict)
+            )
+        time_col = next(
+            (col for col in self.datasource.columns if col.column_name in 
names), None
+        )
+        is_calendar = getattr(self.datasource, "is_calendar_date_column", None)
+        return bool(callable(is_calendar) and is_calendar(time_col))
+
+    def _resample_display_bound(
+        self, bound: datetime | None, df: DataFrame
+    ) -> datetime | None:
+        """Align explicit instants with a datasource's normalized display 
frame."""
+        if bound is None or bound.utcoffset() is None or self.datasource is 
None:
+            return bound
+        if self._is_resample_calendar_column():
+            return bound.replace(tzinfo=None)
+        get_timezone = getattr(self.datasource, "get_dataset_timezone", None)
+        dataset_timezone = get_timezone() if callable(get_timezone) else None
+        if isinstance(dataset_timezone, str):
+            try:
+                return 
bound.astimezone(ZoneInfo(dataset_timezone)).replace(tzinfo=None)
+            except ZoneInfoNotFoundError:

Review Comment:
   Nit: `{"timezone": ""}` in dataset extra reaches `ZoneInfo("")`, which 
raises an uncaught `ValueError` for `fill_time_range` charts with an 
explicit-offset range; `adjust_time_bounds` and `normalize_dttm_col` treat an 
empty name as unset.
   
   ```suggestion
           if isinstance(dataset_timezone, str) and dataset_timezone:
               try:
                   return 
bound.astimezone(ZoneInfo(dataset_timezone)).replace(tzinfo=None)
               except ZoneInfoNotFoundError:
   ```



-- 
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]

Reply via email to