diff --git a/src/pingouin/correlation.py b/src/pingouin/correlation.py index 4d889d7a..582b52e4 100644 --- a/src/pingouin/correlation.py +++ b/src/pingouin/correlation.py @@ -830,7 +830,7 @@ def partial_corr( "pearson", "spearman", ], 'only "pearson" and "spearman" are supported for partial correlation.' - assert isinstance(data, pd.DataFrame), "data must be a pandas DataFrame." + assert hasattr(data, "__dataframe__"), "Data must be compatible with DataFrame" assert data.shape[0] > 2, "Data must have at least 3 samples." if covar is not None and (x_covar is not None or y_covar is not None): raise ValueError("Cannot specify both covar and {x,y}_covar.") @@ -1189,7 +1189,7 @@ def rm_corr(data=None, x=None, y=None, subject=None): from pingouin import ancova, power_corr # Safety checks - assert isinstance(data, pd.DataFrame), "Data must be a DataFrame" + assert hasattr(data, "__dataframe__"), "Data must be compatible with DataFrame" assert x in data.columns, "The %s column is not in data." % x assert y in data.columns, "The %s column is not in data." % y assert data[x].dtype.kind in "bfiu", "%s must be numeric." % x diff --git a/src/pingouin/distribution.py b/src/pingouin/distribution.py index 1ddf0c58..9e8d128b 100644 --- a/src/pingouin/distribution.py +++ b/src/pingouin/distribution.py @@ -207,13 +207,16 @@ def normality(data, dv=None, group=None, method="shapiro", alpha=0.05): Pre 0.304021 0.858979 True Post 1.265656 0.531088 True """ - assert isinstance(data, (pd.DataFrame, pd.Series, list, np.ndarray)) + assert isinstance(data, (pd.DataFrame, pd.Series, list, np.ndarray)) or hasattr( + data, "__dataframe__" + ) assert method in ["shapiro", "normaltest", "jarque_bera"] if isinstance(data, pd.Series): data = data.to_frame() col_names = ["W", "pval"] func = getattr(scipy.stats, method) - if isinstance(data, (list, np.ndarray)): + # Check if the data is 1D array-like + if isinstance(data, (list, np.ndarray)) or (hasattr(data, "__array__") and data.ndim == 1): data = np.asarray(data) assert data.ndim == 1, "Data must be 1D." assert data.size > 3, "Data must have more than 3 samples." @@ -222,7 +225,7 @@ def normality(data, dv=None, group=None, method="shapiro", alpha=0.05): stats.columns = col_names stats["normal"] = np.where(stats["pval"] > alpha, True, False) else: - # Data is a Pandas DataFrame + # Any other kind of data is assumed to be DataFrame-like if dv is None and group is None: # Wide-format # Get numeric data only