Cramer's V recently began throwing an error.
import pandas as pd
df = pd.read_fwf('http://archive.ics.uci.edu/ml/machine-learning-databases/auto-mpg/auto-mpg.data', header=None)
df.columns=['mpg','cylinders','displacement',
'horsepower','weight','acceleration',
'model_year','origin','car_name']
df_clean = df.dropna()
nominal.cramers_v(df_clean[['model_year']],df_clean[['car_name']])
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-24-c52c2b81dd0a> in <module>
----> 1 nominal.cramers_v(df_clean[['model_year']],df_clean[['car_name']])
~/apps/anaconda3/lib/python3.7/site-packages/dython/nominal.py in cramers_v(x, y, nan_strategy, nan_replace_value)
78 elif nan_strategy == DROP:
79 x, y = remove_incomplete_samples(x, y)
---> 80 confusion_matrix = pd.crosstab(x,y)
81 chi2 = ss.chi2_contingency(confusion_matrix)[0]
82 n = confusion_matrix.sum().sum()
~/.local/lib/python3.7/site-packages/pandas/core/reshape/pivot.py in crosstab(index, columns, values, rownames, colnames, aggfunc, margins, margins_name, dropna, normalize)
560 from pandas import DataFrame
561
--> 562 df = DataFrame(data, index=common_idx)
563 if values is None:
564 df["__dummy__"] = 0
~/.local/lib/python3.7/site-packages/pandas/core/frame.py in __init__(self, data, index, columns, dtype, copy)
408 )
409 elif isinstance(data, dict):
--> 410 mgr = init_dict(data, index, columns, dtype=dtype)
411 elif isinstance(data, ma.MaskedArray):
412 import numpy.ma.mrecords as mrecords
~/.local/lib/python3.7/site-packages/pandas/core/internals/construction.py in init_dict(data, index, columns, dtype)
255 arr if not is_datetime64tz_dtype(arr) else arr.copy() for arr in arrays
256 ]
--> 257 return arrays_to_mgr(arrays, data_names, index, columns, dtype=dtype)
258
259
~/.local/lib/python3.7/site-packages/pandas/core/internals/construction.py in arrays_to_mgr(arrays, arr_names, index, columns, dtype)
75 # figure out the index, if necessary
76 if index is None:
---> 77 index = extract_index(arrays)
78 else:
79 index = ensure_index(index)
~/.local/lib/python3.7/site-packages/pandas/core/internals/construction.py in extract_index(data)
356
357 if not indexes and not raw_lengths:
--> 358 raise ValueError("If using all scalar values, you must pass an index")
359
360 if have_series:
ValueError: If using all scalar values, you must pass an index