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


##########
superset/utils/csv.py:
##########
@@ -115,6 +130,32 @@ def escape_values(v: Any) -> Union[str, Any]:
                 if isinstance(value, str):
                     df.at[label, name] = escape_value(value)
 
+    # Row labels and axis names are written out whenever the caller asks for 
the
+    # index, which both export paths do once post-processing has replaced the
+    # range index: pivot_table_v2 promotes the row dimension's warehouse values
+    # into index labels and the dimension name into ``index.name``. Escaping
+    # happens after the cell loop so the labels ``.at`` addresses stay the ones
+    # the frame was handed over with. Every level of a MultiIndex is covered;
+    # the axis names are a separate attribute, hence the ``rename_axis``. This
+    # mirrors the four places ``superset.utils.excel.quote_formulas`` covers
+    # for the xlsx writer.
+    index = df.index
+    if isinstance(index, pd.MultiIndex):
+        # ``levels`` carries each level's distinct values, so an index with
+        # nothing to escape is recognised without a pass over every row.
+        if any(needs_escaping(level) for level in index.levels):
+            index = pd.MultiIndex.from_arrays(
+                [
+                    escape_axis_level(index.get_level_values(position))

Review Comment:
   When a MultiIndex has one hostile label, every other level is rebuilt 
through `get_level_values`, which turns an integer level holding a missing 
value into `float64`. With `MultiIndex.from_tuples([("=a", 5), ("safe", None)], 
names=["dim", "id"])` the id column now exports as `5.0` (and a large id such 
as `9007199254740993` as `9007199254740992.0`), where master writes `5` / 
`9007199254740993`. The safe level is the one that should come through 
untouched, so could the rebuild use the already-escaped level only for levels 
that need it and take the others from 
`index.levels[position].take(index.codes[position])` (or 
`index.get_level_values` only when `needs_escaping`)? A test with a nullable 
integer sibling level would pin it.



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