Skip to content

back to OpenHands summary

OpenHands: statsmodels

Failed to run pytests for test statsmodels

ERROR: while parsing the following warning configuration:

  error::statsmodels.tools.sm_exceptions.HypothesisTestWarning

This error occurred:

Traceback (most recent call last):
  File "/testbed/.venv/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1917, in parse_warning_filter
    category: type[Warning] = _resolve_warning_category(category_)
  File "/testbed/.venv/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1955, in _resolve_warning_category
    m = __import__(module, None, None, [klass])
  File "/testbed/statsmodels/__init__.py", line 1, in <module>
    from statsmodels.compat.patsy import monkey_patch_cat_dtype
  File "/testbed/statsmodels/compat/__init__.py", line 3, in <module>
    from .python import (
ImportError: cannot import name 'asbytes' from 'statsmodels.compat.python' (/testbed/statsmodels/compat/python.py)

Patch diff

diff --git a/statsmodels/tools/data.py b/statsmodels/tools/data.py
index 775cf7e25..9e2cfc01a 100644
--- a/statsmodels/tools/data.py
+++ b/statsmodels/tools/data.py
@@ -19,10 +19,46 @@ def interpret_data(data, colnames=None, rownames=None):
     -------
     (values, colnames, rownames) : (homogeneous ndarray, list)
     """
-    pass
+    if data is None:
+        return None, None, None
+
+    if isinstance(data, pd.DataFrame):
+        values = data.values
+        if colnames is None:
+            colnames = data.columns.tolist()
+        if rownames is None:
+            rownames = data.index.tolist()
+    elif isinstance(data, pd.Series):
+        values = data.values[:, None]
+        if colnames is None:
+            colnames = [data.name]
+        if rownames is None:
+            rownames = data.index.tolist()
+    else:
+        values = np.asarray(data)
+        if values.ndim == 1:
+            values = values[:, None]
+        if colnames is None and values.dtype.names:
+            colnames = list(values.dtype.names)
+
+    if colnames is None:
+        colnames = ['Y_%d' % i for i in range(values.shape[1])]
+
+    return values, colnames, rownames

 def _is_recarray(data):
     """
     Returns true if data is a recarray
     """
-    pass
\ No newline at end of file
+    return isinstance(data, np.recarray) or (isinstance(data, np.ndarray) and data.dtype.names is not None)
+
+def _is_using_pandas(data, none_on_fail=False):
+    """
+    Returns True if data is a pandas object (Series or DataFrame)
+    """
+    if none_on_fail:
+        try:
+            return isinstance(data, (pd.Series, pd.DataFrame))
+        except:
+            return None
+    return isinstance(data, (pd.Series, pd.DataFrame))
\ No newline at end of file