feat: generate label map on the backend (#21124)

This commit is contained in:
Yongjie Zhao
2022-08-22 21:00:02 +08:00
committed by GitHub
parent 756ed0e36a
commit 11bf7b9125
8 changed files with 154 additions and 2 deletions

View File

@@ -33,6 +33,10 @@ from superset.utils.pandas_postprocessing.resample import resample
from superset.utils.pandas_postprocessing.rolling import rolling
from superset.utils.pandas_postprocessing.select import select
from superset.utils.pandas_postprocessing.sort import sort
from superset.utils.pandas_postprocessing.utils import (
escape_separator,
unescape_separator,
)
__all__ = [
"aggregate",
@@ -52,4 +56,6 @@ __all__ = [
"select",
"sort",
"flatten",
"escape_separator",
"unescape_separator",
]

View File

@@ -22,6 +22,7 @@ from numpy.distutils.misc_util import is_sequence
from superset.utils.pandas_postprocessing.utils import (
_is_multi_index_on_columns,
escape_separator,
FLAT_COLUMN_SEPARATOR,
)
@@ -86,8 +87,8 @@ def flatten(
_cells = []
for cell in series if is_sequence(series) else [series]:
if pd.notnull(cell):
# every cell should be converted to string
_cells.append(str(cell))
# every cell should be converted to string and escape comma
_cells.append(escape_separator(str(cell)))
_columns.append(FLAT_COLUMN_SEPARATOR.join(_cells))
df.columns = _columns

View File

@@ -198,3 +198,13 @@ def _append_columns(
return _base_df
append_df = append_df.rename(columns=columns)
return pd.concat([base_df, append_df], axis="columns")
def escape_separator(plain_str: str, sep: str = FLAT_COLUMN_SEPARATOR) -> str:
char = sep.strip()
return plain_str.replace(char, "\\" + char)
def unescape_separator(escaped_str: str, sep: str = FLAT_COLUMN_SEPARATOR) -> str:
char = sep.strip()
return escaped_str.replace("\\" + char, char)