File tree Expand file tree Collapse file tree 3 files changed +17
-7
lines changed Expand file tree Collapse file tree 3 files changed +17
-7
lines changed Original file line number Diff line number Diff line change 31
31
"get_cached_doc" ,
32
32
"call_cached_func" ,
33
33
"PD_LT_1_4" ,
34
+ "PD_LT_2" ,
34
35
]
35
36
36
37
version = parse (pd .__version__ )
37
38
38
39
PD_LT_1_0_0 = version < Version ("1.0.0" )
39
40
PD_LT_1_4 = version < Version ("1.3.99" )
41
+ PD_LT_2 = version < Version ("1.9.99" )
40
42
41
43
try :
42
44
from pandas .api .types import is_numeric_dtype
Original file line number Diff line number Diff line change @@ -121,7 +121,9 @@ def test_settingwithcopywarning(self):
121
121
with warnings .catch_warnings (record = True ) as ws :
122
122
warnings .simplefilter ('always' )
123
123
miceData .update_all ()
124
-
124
+ # Only include pandas warnings. There are many from patsy
125
+ # and sometimes warnings from other packages here
126
+ ws = [w for w in ws if "\\ pandas\\ " in w .filename ]
125
127
assert len (ws ) == 0
126
128
127
129
def test_next_sample (self ):
Original file line number Diff line number Diff line change 1
1
from statsmodels .compat .pandas import Appender , is_numeric_dtype
2
2
from statsmodels .compat .scipy import SP_LT_19
3
-
3
+ from statsmodels . compat . pandas import PD_LT_2
4
4
from typing import Sequence , Union
5
5
6
6
import numpy as np
7
7
import pandas as pd
8
- from pandas .core .dtypes .common import is_categorical_dtype
8
+ if PD_LT_2 :
9
+ from pandas .core .dtypes .common import is_categorical_dtype
10
+ else :
11
+ # After pandas 2 is the minium, use the isinstance check
12
+ def is_categorical_dtype (dtype ):
13
+ return isinstance (dtype , pd .CategoricalDtype )
14
+
9
15
from scipy import stats
10
16
11
17
from statsmodels .iolib .table import SimpleTable
@@ -392,10 +398,10 @@ def numeric(self) -> pd.DataFrame:
392
398
q = stats .norm .ppf (1.0 - self ._alpha / 2 )
393
399
394
400
def _mode (ser ):
395
- if SP_LT_19 :
396
- mode_res = stats . mode ( ser .dropna ())
397
- else :
398
- mode_res = stats .mode (ser . dropna (), keepdims = True )
401
+ dtype = ser . dtype if isinstance ( ser . dtype , np . dtype ) else ser . dtype . numpy_dtype
402
+ ser_no_missing = ser .dropna (). to_numpy ( dtype = dtype )
403
+ kwargs = {} if SP_LT_19 else { "keepdims" : True }
404
+ mode_res = stats .mode (ser_no_missing , ** kwargs )
399
405
# Changes in SciPy 1.10
400
406
if np .isscalar (mode_res [0 ]):
401
407
return float (mode_res [0 ]), mode_res [1 ]
You can’t perform that action at this time.
0 commit comments