bito-code-review[bot] commented on PR #43693:
URL: https://github.com/apache/superset/pull/43693#issuecomment-5469731144

   <!-- Bito Reply -->
   The issue is that `df[index].fillna(value=NULL_STRING)` fails when the index 
column is of type `Categorical`, as `NULL_STRING` is not in the existing 
categories. To resolve this, you must ensure the category is added before 
filling.
   
   Here is the corrected implementation for 
`superset/utils/pandas_postprocessing/pivot.py`:
   
   ```python
       # Fill NULL/NaN values in the index columns with NULL_STRING so that
       # NULL grouping keys survive as a real "<NULL>" row in the pivot output.
       for col in index:
           if df[col].dtype.name == "category" and NULL_STRING not in 
df[col].cat.categories:
               df[col] = df[col].cat.add_categories([NULL_STRING])
       df[index] = df[index].fillna(value=NULL_STRING)
   ```
   
   This approach safely handles categorical data by adding the missing category 
before performing the fill operation. There are no other comments on this PR to 
address.
   
   **superset/utils/pandas_postprocessing/pivot.py**
   ```
   for col in index:
           if df[col].dtype.name == "category" and NULL_STRING not in 
df[col].cat.categories:
               df[col] = df[col].cat.add_categories([NULL_STRING])
       df[index] = df[index].fillna(value=NULL_STRING)
   ```


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