Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Bad date type in email text report for table chart #20119

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion superset/utils/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
import logging
import re
import urllib.request
from typing import Any, Dict, Optional
Expand All @@ -22,6 +23,10 @@
import pandas as pd
import simplejson

from superset.utils.core import GenericDataType

logger = logging.getLogger(__name__)

negative_number_re = re.compile(r"^-[0-9.]+$")

# This regex will match if the string starts with:
Expand Down Expand Up @@ -97,11 +102,22 @@ def get_chart_dataframe(
return None

result = simplejson.loads(content.decode("utf-8"))

# need to convert float value to string to show full long number
pd.set_option("display.float_format", lambda x: str(x))
df = pd.DataFrame.from_dict(result["result"][0]["data"])

try:
# if any column type is equal to 2, need to convert data into
# datetime timestamp for that column.
if GenericDataType.TEMPORAL in result["result"][0]["coltypes"]:
for i in range(len(result["result"][0]["coltypes"])):
if result["result"][0]["coltypes"][i] == GenericDataType.TEMPORAL:
df[result["result"][0]["colnames"][i]] = df[
result["result"][0]["colnames"][i]
].astype("datetime64[ms]")
except BaseException as err:
logger.error(err)

# rebuild hierarchical columns and index
df.columns = pd.MultiIndex.from_tuples(
tuple(colname) if isinstance(colname, list) else (colname,)
Expand Down
1 change: 1 addition & 0 deletions tests/integration_tests/reports/commands_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,7 @@ def test_email_chart_report_schedule_with_text(
},
"colnames": [("t1",), ("t2",), ("t3__sum",)],
"indexnames": [(0,), (1,)],
"coltypes": [1, 1],
},
],
}
Expand Down