Skip to content

Commit

Permalink
Merge pull request #8797 from bashtage/improve-warning-check
Browse files Browse the repository at this point in the history
MAINT: Improve specificity of warning check
  • Loading branch information
bashtage committed Apr 14, 2023
2 parents 4afdb22 + fe89b56 commit ad35f85
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
2 changes: 2 additions & 0 deletions statsmodels/compat/pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@
"get_cached_doc",
"call_cached_func",
"PD_LT_1_4",
"PD_LT_2",
]

version = parse(pd.__version__)

PD_LT_1_0_0 = version < Version("1.0.0")
PD_LT_1_4 = version < Version("1.3.99")
PD_LT_2 = version < Version("1.9.99")

try:
from pandas.api.types import is_numeric_dtype
Expand Down
4 changes: 3 additions & 1 deletion statsmodels/imputation/tests/test_mice.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ def test_settingwithcopywarning(self):
with warnings.catch_warnings(record=True) as ws:
warnings.simplefilter('always')
miceData.update_all()

# Only include pandas warnings. There are many from patsy
# and sometimes warnings from other packages here
ws = [w for w in ws if "\\pandas\\" in w.filename]
assert len(ws) == 0

def test_next_sample(self):
Expand Down
18 changes: 12 additions & 6 deletions statsmodels/stats/descriptivestats.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
from statsmodels.compat.pandas import Appender, is_numeric_dtype
from statsmodels.compat.scipy import SP_LT_19

from statsmodels.compat.pandas import PD_LT_2
from typing import Sequence, Union

import numpy as np
import pandas as pd
from pandas.core.dtypes.common import is_categorical_dtype
if PD_LT_2:
from pandas.core.dtypes.common import is_categorical_dtype
else:
# After pandas 2 is the minium, use the isinstance check
def is_categorical_dtype(dtype):
return isinstance(dtype, pd.CategoricalDtype)

from scipy import stats

from statsmodels.iolib.table import SimpleTable
Expand Down Expand Up @@ -392,10 +398,10 @@ def numeric(self) -> pd.DataFrame:
q = stats.norm.ppf(1.0 - self._alpha / 2)

def _mode(ser):
if SP_LT_19:
mode_res = stats.mode(ser.dropna())
else:
mode_res = stats.mode(ser.dropna(), keepdims=True)
dtype = ser.dtype if isinstance(ser.dtype, np.dtype) else ser.dtype.numpy_dtype
ser_no_missing = ser.dropna().to_numpy(dtype=dtype)
kwargs = {} if SP_LT_19 else {"keepdims": True}
mode_res = stats.mode(ser_no_missing, **kwargs)
# Changes in SciPy 1.10
if np.isscalar(mode_res[0]):
return float(mode_res[0]), mode_res[1]
Expand Down

0 comments on commit ad35f85

Please sign in to comment.