Skip to content

Commit

Permalink
Merge pull request #8777 from josef-pkt/try_unittest
Browse files Browse the repository at this point in the history
MAINT/TST  unit test failures, compatibility changes
  • Loading branch information
josef-pkt committed Apr 7, 2023
2 parents 712e5dd + aeafb7b commit 4273c0d
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 17 deletions.
4 changes: 2 additions & 2 deletions statsmodels/formula/tests/test_formula.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def test_formula_predict_series():

result = results.predict({"x": [1, 2, 3]})
expected = pd.Series([1., 2., 3.], index=[0, 1, 2])
assert_series_equal(result, expected)
assert_series_equal(result, expected, check_index_type=False)


def test_patsy_lazy_dict():
Expand Down Expand Up @@ -210,7 +210,7 @@ def test_patsy_missing_data():
assert 'ValueWarning' in repr(w[-1].message)
assert 'nan values have been dropped' in repr(w[-1].message)
# Frist record will be dropped in both cases
assert_equal(res.fittedvalues, res2)
assert_equal(res.fittedvalues, res2, check_index_type=False)


def test_predict_nondataframe():
Expand Down
8 changes: 4 additions & 4 deletions statsmodels/iolib/tests/test_table.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import numpy as np

from numpy.testing import assert_equal
from statsmodels.iolib.table import SimpleTable, default_txt_fmt
from statsmodels.iolib.table import default_latex_fmt
Expand Down Expand Up @@ -207,8 +207,8 @@ def test_regression_with_tuples(self):
exo = df.join(x)
endo_groups = endo.groupby("i")
exo_groups = exo.groupby("i")
exo_df = exo_groups.agg([np.sum, np.max])
endo_df = endo_groups.agg([np.sum, np.max])
exo_df = exo_groups.agg(['sum', 'max'])
endo_df = endo_groups.agg(['sum', 'max'])
reg = OLS(exo_df[[("x", "sum")]], endo_df).fit()
interesting_lines = []
import warnings
Expand All @@ -221,7 +221,7 @@ def test_regression_with_tuples(self):

desired = ["Dep. Variable: x_sum ",
"y_sum 1.4595 0.209 ",
"y_amax 0.2432 0.035 "]
"y_max 0.2432 0.035 "]

assert_equal(sorted(desired), sorted(interesting_lines))

Expand Down
20 changes: 15 additions & 5 deletions statsmodels/tools/rootfinding.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import numpy as np
from scipy import optimize

from statsmodels.tools.testing import Holder

DEBUG = False


Expand Down Expand Up @@ -202,11 +204,19 @@ def brentq_expanding(func, low=None, upp=None, args=(), xtol=1e-5,
full_output=full_output)
if full_output:
val = res[0]
info = res[1]
info.iterations_expand = n_it
info.start_bounds = (sl, su)
info.brentq_bounds = (left, right)
info.increasing = increasing
info = Holder(
# from brentq
root=res[1].root,
iterations=res[1].iterations,
function_calls=res[1].function_calls,
converged=res[1].converged,
flag=res[1].flag,
# ours:
iterations_expand=n_it,
start_bounds=(sl, su),
brentq_bounds=(left, right),
increasing=increasing,
)
return val, info
else:
return res
10 changes: 5 additions & 5 deletions statsmodels/tools/tests/test_rootfinding.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ def test_brentq_expanding():
assert_allclose(val, a, rtol=1e-5)
info1 = {'iterations': 63, 'start_bounds': (-1, 1),
'brentq_bounds': (100, 1000), 'flag': 'converged',
'function_calls': 64, 'iterations_expand': 3, 'converged': True}
'function_calls': 64, 'iterations_expand': 3, 'converged': True,
}

# adjustments for scipy 0.8.0 with changed convergence criteria
assert_array_less(info.__dict__['iterations'], 70)
assert_array_less(info.__dict__['function_calls'], 70)
assert_array_less(info.iterations, 70)
assert_array_less(info.function_calls, 70)
for k in info1:
if k in ['iterations', 'function_calls']:
continue
assert_equal(info1[k], info.__dict__[k])
assert_equal(info1[k], getattr(info, k))

assert_allclose(info.root, a, rtol=1e-5)
2 changes: 1 addition & 1 deletion statsmodels/tsa/tests/test_deterministic.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ def test_range_index_basic():


def test_range_casting():
idx = np.arange(120)
idx = np.arange(120).astype(np.int64)
dp = DeterministicProcess(
idx, constant=True, order=1, seasonal=True, period=12
)
Expand Down

0 comments on commit 4273c0d

Please sign in to comment.