Skip to content

Commit

Permalink
MAINT: Remove FutureWarnings
Browse files Browse the repository at this point in the history
Remove future warnings from pandas, NumPy and internal
  • Loading branch information
bashtage committed Jul 24, 2020
1 parent c8dcd23 commit d8c16fb
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 77 deletions.
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ filterwarnings =
error:Only PeriodIndexes, DatetimeIndexes:UserWarning
error:the 'unbiased'' keyword is deprecated:FutureWarning
error:unbiased is deprecated in factor of adjusted:FutureWarning
error:categorical is deprecated:FutureWarning
error:After 0.13 initialization:FutureWarning
markers =
example: mark a test that runs example code
matplotlib: mark a test that requires matplotlib
Expand Down
13 changes: 7 additions & 6 deletions statsmodels/discrete/discrete_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,16 @@

# helper for MNLogit (will be generally useful later)
def _numpy_to_dummies(endog):
if endog.dtype.kind in ['S', 'O']:
endog_dummies, ynames = tools.categorical(endog, drop=True,
dictnames=True)
elif endog.ndim == 2:
if endog.ndim == 2 and endog.dtype.kind not in ["S", "O"]:
endog_dummies = endog
ynames = range(endog.shape[1])
else:
endog_dummies, ynames = tools.categorical(endog, drop=True,
dictnames=True)
dummies = get_dummies(endog, drop_first=False)
ynames = {i: dummies.columns[i] for i in range(dummies.shape[1])}
endog_dummies = np.asarray(dummies, dtype=float)

return endog_dummies, ynames

return endog_dummies, ynames


Expand Down
7 changes: 4 additions & 3 deletions statsmodels/imputation/tests/test_ros.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from io import StringIO
from textwrap import dedent

import numpy as np
import numpy.testing as npt

import numpy
Expand Down Expand Up @@ -379,10 +380,10 @@ def test_cohn(self):
'ncen_equal', 'prob_exceedance'
]
cohn = ros.cohn_numbers(self.df, self.rescol, self.cencol)
# Use round in place of the deprecated check_less_precise arg
assert_frame_equal(
cohn[cols],
self.expected_cohn[cols],
check_less_precise=True,
np.round(cohn[cols], 3),
np.round(self.expected_cohn[cols], 3),
)


Expand Down
2 changes: 1 addition & 1 deletion statsmodels/regression/_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __init__(self, endog, exog, weights=1.0, check_endog=False,
if np.isscalar(weights):
self.wexog = w_half * exog
else:
self.wexog = w_half[:, None] * exog
self.wexog = np.asarray(w_half)[:, None] * exog

def fit(self, method='pinv'):
"""
Expand Down
2 changes: 2 additions & 0 deletions statsmodels/tools/tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
from statsmodels.tools import tools
from statsmodels.tools.tools import pinv_extended

# Ignore future warnings from test code
pytestmark = pytest.mark.filterwarnings("ignore:categorical is deprecated:FutureWarning")

@pytest.fixture(scope='module')
def string_var():
Expand Down
2 changes: 1 addition & 1 deletion statsmodels/tsa/ar_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ def _wrap_prediction(self, prediction, start, end):
n_values = end - start
if not isinstance(self.data.orig_endog, (pd.Series, pd.DataFrame)):
return prediction[-n_values:]
index = self.data.orig_endog.index
index = self._index
if end > self.endog.shape[0]:
freq = getattr(index, 'freq', None)
if freq:
Expand Down
2 changes: 1 addition & 1 deletion statsmodels/tsa/deterministic.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ def _compute_ratio(
) -> np.ndarray:
if isinstance(index, pd.PeriodIndex):
index = index.to_timestamp()
delta = index.to_perioddelta(self._freq)
delta = index - index.to_period(self._freq).to_timestamp()
pi = index.to_period(self._freq)
gap = (pi + 1).to_timestamp() - pi.to_timestamp()
return to_numpy(delta) / to_numpy(gap)
Expand Down
8 changes: 4 additions & 4 deletions statsmodels/tsa/holtwinters/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,17 +403,17 @@ def fix_params(self, values):

def _initialize(self):
if self._initialization_method is None:
warnings.warn(
"After 0.13 initialization must be handled at model creation",
FutureWarning,
)
msg = "initial_{0} given but no initialization method specified."
if self._initial_level is not None:
raise ValueError(msg.format("level"))
if self._initial_trend is not None:
raise ValueError(msg.format("trend"))
if self._initial_seasonal is not None:
raise ValueError(msg.format("seasonal"))
warnings.warn(
"After 0.13 initialization must be handled at model creation",
FutureWarning,
)
return
if self._initialization_method == "known":
return self._initialize_known()
Expand Down
Loading

0 comments on commit d8c16fb

Please sign in to comment.