Skip to content

Commit

Permalink
Fix nullable dtypes not compatible with Altair (#250)
Browse files Browse the repository at this point in the history
* Patch config

* Fix bug with new Pandas nullable dtype
  • Loading branch information
westernguy2 committed Feb 3, 2021
1 parent 5cfd44c commit 2ea95d8
Showing 1 changed file with 4 additions and 0 deletions.
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

0 comments on commit 2ea95d8

Please sign in to comment.