Repository: evidentlyai/evidently
Issue: Chi-square fails on categorical data
Root cause: Validation Gap

I tried using the chi-squared test, but I observed that it only works on numerical columns. When I try using categoricals, it fails. Here's how to reproduce. 

```python
def synthetic_interaction_data(n, yintercept = 10):
    df = pd.DataFrame()
    df["id"] = range(n)
    df[f'x1'] = np.random.random(size=n)*10
    df[f'x2'] = np.random.random(size=n)*10
    df[f'x3'] = np.random.random(size=n)*10
    df['target'] = (df['x1']**2 + df['x1']*df['x2'] + 5*df['x1']*np.sin(3*df['x2'])  + yintercept).astype("int16") % 2
    return df

df = synthetic_interaction_data(2000)
df["odd"] = "even"
df.loc[np.floor(df["x1"]) % 2 == 1, "odd"] = "odd"
df['target'] = df['target'].astype(np.object)

df2 = synthetic_interaction_data(2000)
df2["odd"] = "even"
df2.loc[np.floor(df2["x1"]) % 2 == 1, "odd"] = "odd"
df2['target'] = df2['target'].astype(np.object)

ddp = Profile(sections=[DataDriftProfileSection])
ddp.calculate(df, df2, column_mapping = None)
```

Shows the error below:
```
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-70-92e6117fd55f> in <module>
      1 ddp = Profile(sections=[DataDriftProfileSection])
----> 2 ddp.calculate(df, df2, column_mapping = None)

/opt/conda/lib/python3.8/site-packages/evidently/model_profile/model_profile.py in calculate(self, reference_data, current_data, column_mapping)
     20                   current_data: pandas.DataFrame,
     21                   column_mapping: dict = None):
---> 22         self.execute(reference_data, current_data, column_mapping)
     23 
     24     def get_analyzers(self):

/opt/conda/lib/python3.8/site-packages/evidently/pipeline/pipeline.py in execute(self, reference_data, current_data, column_mapping)
     16                 column_mapping: dict = None):
     17         for analyzer in self.get_analyzers():
---> 18             self.analyzers_results[analyzer] = analyzer().calculate(reference_data, current_data, column_mapping)

/opt/conda/lib/python3.8/site-packages/evidently/analyzers/data_drift_analyzer.py in calculate(self, reference_data, current_data, column_mapping)
     57 
     58         for feature_name in cat_feature_names:
---> 59             ref_feature_vc = reference_data[feature_name][np.isfinite(reference_data[feature_name])].value_counts()
     60             current_feature_vc = current_data[feature_name][np.isfinite(current_data[feature_name])].value_counts()
     61 

/opt/conda/lib/python3.8/site-packages/pandas/core/generic.py in __array_ufunc__(self, ufunc, method, *inputs, **kwargs)
   1934         self, ufunc: Callable, method: str, *inputs: Any, **kwargs: Any
   1935     ):
-> 1936         return arraylike.array_ufunc(self, ufunc, method, *inputs, **kwargs)
   1937 
   1938     # ideally we would define this to avoid the getattr checks, but

/opt/conda/lib/python3.8/site-packages/pandas/core/arraylike.py in array_ufunc(self, ufunc, method, *inputs, **kwargs)
    356         # ufunc(series, ...)
    357         inputs = tuple(extract_array(x, extract_numpy=True) for x in inputs)
--> 358         result = getattr(ufunc, method)(*inputs, **kwargs)
    359     else:
    360         # ufunc(dataframe)

TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
```

Hope you can help me with this, or if there's something I did incorrectly. Thanks. 

One thing I tried is encoding them to codes and it worked. Any recommendations and suggestions would be welcome. 

Hi @mabreyes thanks for noting, and glad you solved the issue! For now, that is exactly how this feature works: one needs to encode categorical features with numerical labels. We expect to adapt the tool to work with categorical data at a later point. Here is a step by step guide that covers some of the pre-processing steps one might need to perform for some reports/data types: https://docs.evidentlyai.com/step-by-step-guide-for-jupyter-notebooks

@elenasamuylova Thanks so much. Closing this issue for now.