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 nullable dtypes not compatible with Altair #250

Merged
merged 3 commits into from
Feb 3, 2021
Merged
Changes from all 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
4 changes: 4 additions & 0 deletions lux/vislib/altair/AltairChart.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import pandas as pd
import numpy as np
import altair as alt
from lux.utils.date_utils import compute_date_granularity

Expand Down Expand Up @@ -117,6 +118,9 @@ def initialize_chart(self):
@classmethod
def sanitize_dataframe(self, df):
for attr in df.columns:
if pd.api.types.is_float_dtype(df[attr].dtype): # Check if dtype is unrecognized by Altair
df[attr] = df[attr].astype(np.float64)

# Altair can not visualize non-string columns
# convert all non-string columns in to strings
df = df.rename(columns={attr: str(attr)})
Expand Down