mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
fix: convert <NA> values to None instead of stringifying (#22321)
This commit is contained in:
committed by
GitHub
parent
6d3591cb9e
commit
1c20206057
@@ -18,6 +18,13 @@
|
||||
# pylint: disable=import-outside-toplevel, unused-argument
|
||||
|
||||
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
from numpy.core.multiarray import array
|
||||
|
||||
from superset.result_set import stringify_values
|
||||
|
||||
|
||||
def test_column_names_as_bytes() -> None:
|
||||
"""
|
||||
Test that we can handle column names as bytes.
|
||||
@@ -65,3 +72,37 @@ def test_column_names_as_bytes() -> None:
|
||||
| 1 | 2016-01-27 | 392.444 | 396.843 | 391.782 | 394.972 | 394.972 | 47424400 |
|
||||
""".strip()
|
||||
)
|
||||
|
||||
|
||||
def test_stringify_with_null_integers():
|
||||
"""
|
||||
Test that we can safely handle type errors when an integer column has a null value
|
||||
"""
|
||||
|
||||
data = [
|
||||
("foo", "bar", pd.NA, None),
|
||||
("foo", "bar", pd.NA, True),
|
||||
("foo", "bar", pd.NA, None),
|
||||
]
|
||||
numpy_dtype = [
|
||||
("id", "object"),
|
||||
("value", "object"),
|
||||
("num", "object"),
|
||||
("bool", "object"),
|
||||
]
|
||||
|
||||
array2 = np.array(data, dtype=numpy_dtype)
|
||||
column_names = ["id", "value", "num", "bool"]
|
||||
|
||||
result_set = np.array([stringify_values(array2[column]) for column in column_names])
|
||||
|
||||
expected = np.array(
|
||||
[
|
||||
array(['"foo"', '"foo"', '"foo"'], dtype=object),
|
||||
array(['"bar"', '"bar"', '"bar"'], dtype=object),
|
||||
array([None, None, None], dtype=object),
|
||||
array([None, "true", None], dtype=object),
|
||||
]
|
||||
)
|
||||
|
||||
assert np.array_equal(result_set, expected)
|
||||
|
||||
Reference in New Issue
Block a user