Skip to content

Commit f745e5b

Browse files
authored
Merge pull request statsmodels#8825 from bashtage/pre-deprecations
MAINT: Remove casts from array to scalar
2 parents a73f975 + 15a4620 commit f745e5b

31 files changed

+114
-60
lines changed

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ filterwarnings =
7777
error:The probit link alias is deprecated:FutureWarning:
7878
error:Parsing dates in:UserWarning
7979
error:A value is trying to be set on a copy::
80+
error:Conversion of an array with ndim:DeprecationWarning:statsmodels
8081
markers =
8182
example: mark a test that runs example code
8283
matplotlib: mark a test that requires matplotlib

statsmodels/base/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1912,7 +1912,7 @@ def wald_test(self, r_matrix, cov_p=None, invcov=None,
19121912
)
19131913
scalar = False
19141914
if scalar and F.size == 1:
1915-
F = float(F)
1915+
F = float(np.squeeze(F))
19161916
if use_f:
19171917
F /= J
19181918
return ContrastResults(F=F, df_denom=df_resid,

statsmodels/conftest.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,16 @@
1616

1717
logger = logging.getLogger(__name__)
1818

19+
cow = False
1920
try:
2021
cow = bool(os.environ.get("SM_TEST_COPY_ON_WRITE", False))
2122
pd.options.mode.copy_on_write = cow
22-
logger.critical("Copy on Write Enabled!")
2323
except AttributeError:
24+
pass
25+
26+
if cow:
27+
logger.critical("Copy on Write Enabled!")
28+
else:
2429
logger.critical("Copy on Write disabled")
2530

2631

statsmodels/discrete/discrete_model.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2080,7 +2080,7 @@ def hessian(self, params):
20802080

20812081
for i in range(dim):
20822082
for j in range(i + 1):
2083-
hess_arr[i,j] = np.sum(mu * exog[:,i,None] * exog[:,j,None] *
2083+
hess_val = np.sum(mu * exog[:,i,None] * exog[:,j,None] *
20842084
(mu * (a3 * a4 / a1**2 -
20852085
2 * a3**2 * a2 / a1**3 +
20862086
2 * a3 * (a4 + 1) / a1**2 -
@@ -2091,6 +2091,7 @@ def hessian(self, params):
20912091
a4 * (p - 1) / (a1 * mu)) +
20922092
((y - 1) * (1 + a4) / a2 -
20932093
(1 + a4) / a1)), axis=0)
2094+
hess_arr[i, j] = np.squeeze(hess_val)
20942095
tri_idx = np.triu_indices(dim, k=1)
20952096
hess_arr[tri_idx] = hess_arr.T[tri_idx]
20962097

@@ -3447,8 +3448,11 @@ def _hessian_geom(self, params):
34473448
for j in range(dim):
34483449
if j > i:
34493450
continue
3450-
hess_arr[i,j] = np.sum(-exog[:,i,None] * exog[:,j,None] *
3451-
const_arr, axis=0)
3451+
hess_arr[i,j] = np.squeeze(
3452+
np.sum(-exog[:,i,None] * exog[:,j,None] * const_arr,
3453+
axis=0
3454+
)
3455+
)
34523456
tri_idx = np.triu_indices(dim, k=1)
34533457
hess_arr[tri_idx] = hess_arr.T[tri_idx]
34543458
return hess_arr
@@ -3488,9 +3492,13 @@ def _hessian_nb1(self, params):
34883492
for j in range(dim):
34893493
if j > i:
34903494
continue
3491-
hess_arr[i,j] = np.sum(dparams[:,i,None] * dmudb[:,j,None] +
3492-
xmu_alpha[:,i,None] * xmu_alpha[:,j,None] *
3493-
trigamma, axis=0)
3495+
hess_arr[i,j] = np.squeeze(
3496+
np.sum(
3497+
dparams[:,i,None] * dmudb[:,j,None] +
3498+
xmu_alpha[:,i,None] * xmu_alpha[:,j,None] * trigamma,
3499+
axis=0
3500+
)
3501+
)
34943502
tri_idx = np.triu_indices(dim, k=1)
34953503
hess_arr[tri_idx] = hess_arr.T[tri_idx]
34963504

statsmodels/discrete/tests/test_truncated_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ def test_predict(self):
359359
rtol=5e-4, atol=5e-4)
360360

361361
prob_main = res1.results_count.predict(ex, which="prob")[0] * prob_nz
362-
prob_main[0] = prob_zero
362+
prob_main[0] = np.squeeze(prob_zero)
363363
assert_allclose(prob_main[:4], res2.predict_prob, rtol=5e-4, atol=5e-4)
364364

365365
assert_allclose(mean_main * prob_nz, res2.predict_mean,

statsmodels/emplike/elanova.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def compute_ANOVA(self, mu=None, mu_start=0, return_weights=0):
113113
res = optimize.fmin_powell(self._opt_common_mu, mu_start,
114114
full_output=1, disp=False)
115115
llr = res[1]
116-
mu_common = float(res[0])
116+
mu_common = float(np.squeeze(res[0]))
117117
pval = 1 - chi2.cdf(llr, self.num_groups - 1)
118118
if return_weights:
119119
return llr, pval, mu_common, self.new_weights

statsmodels/genmod/generalized_estimating_equations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2390,7 +2390,7 @@ def setup_ordinal(self, endog, exog, groups, time, offset):
23902390
for thresh_ix, thresh in enumerate(endog_cuts):
23912391

23922392
exog_out[jrow, :] = exog_row
2393-
endog_out[jrow] = (int(endog_value > thresh))
2393+
endog_out[jrow] = int(np.squeeze(endog_value > thresh))
23942394
intercepts[jrow, thresh_ix] = 1
23952395
groups_out[jrow] = group_value
23962396
time_out[jrow] = time_value

statsmodels/graphics/gofplots.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@ def _fmt_probplot_axis(ax, dist, nobs):
985985
axis_qntls = dist.ppf(axis_probs)
986986
ax.set_xticks(axis_qntls)
987987
ax.set_xticklabels(
988-
axis_probs * 100,
988+
[str(lbl) for lbl in (axis_probs * 100)],
989989
rotation=45,
990990
rotation_mode="anchor",
991991
horizontalalignment="right",

statsmodels/graphics/mosaicplot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ def _normalize_dataframe(dataframe, index):
326326
#groupby the given keys, extract the same columns and count the element
327327
# then collapse them with a mean
328328
data = dataframe[index].dropna()
329-
grouped = data.groupby(index, sort=False)
329+
grouped = data.groupby(index, sort=False, observed=False)
330330
counted = grouped[index].count()
331331
averaged = counted.mean(axis=1)
332332
# Fill empty missing with 0, see GH5639

statsmodels/iolib/summary.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919

2020
def forg(x, prec=3):
21+
x = np.squeeze(x)
2122
if prec == 3:
2223
# for 3 decimals
2324
if (abs(x) >= 1e4) or (abs(x) < 1e-4):

0 commit comments

Comments
 (0)