sadpandajoe commented on code in PR #43693:
URL: https://github.com/apache/superset/pull/43693#discussion_r3939265596


##########
superset/utils/pandas_postprocessing/pivot.py:
##########
@@ -187,6 +187,25 @@ def _restore_dropped_metric_columns(
     return df
 
 
+def _fill_dimension_column(df: DataFrame, col: str, fill_value: str) -> None:
+    """Fill missing values in a groupby dimension column before pivoting.
+
+    Handles categorical dtypes (adding fill_value to categories) and datetime
+    dtypes (converting to string representation with fill_value for NaT) to 
prevent
+    dtype errors and preserve NULL/NaN/NaT keys through pivot_table().
+    """
+    s = df[col]
+    if isinstance(s.dtype, pd.CategoricalDtype) and fill_value not in 
s.cat.categories:

Review Comment:
   Adding the fill category even when this dimension has no missing values 
makes `pivot_table()` materialize an unobserved `<NULL>` group (or column) 
under its default `observed=False`, so ordinary categorical pivots gain a 
zero-valued bucket that was not in the input. Could this only add the category 
when `s.isna().any()`?



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