Skip to content

Commit

Permalink
CLN: Remove compat nanmean
Browse files Browse the repository at this point in the history
Drop compat version of nanmean in favor of standard implementation
  • Loading branch information
bashtage committed Jun 28, 2017
1 parent cb9a837 commit 6cb6d49
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
1 change: 0 additions & 1 deletion statsmodels/compat/numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import numpy as np

np_matrix_rank = np.linalg.matrix_rank
nanmean = np.nanmean

if NumpyVersion(np.__version__) >= '1.9.0':
np_new_unique = np.unique
Expand Down
7 changes: 3 additions & 4 deletions statsmodels/multivariate/pca.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import pandas as pd

from statsmodels.compat.python import range
from statsmodels.compat.numpy import nanmean
from statsmodels.tools.sm_exceptions import (ValueWarning,
EstimationWarning)

Expand Down Expand Up @@ -409,8 +408,8 @@ def _prepare_data(self):
if np.all(np.isnan(adj_data)):
return np.empty(adj_data.shape[1]).fill(np.nan)

self._mu = nanmean(adj_data, axis=0)
self._sigma = np.sqrt(nanmean((adj_data - self._mu) ** 2.0, axis=0))
self._mu = np.nanmean(adj_data, axis=0)
self._sigma = np.sqrt(np.nanmean((adj_data - self._mu) ** 2.0, axis=0))
if self._standardize:
data = (adj_data - self._mu) / self._sigma
elif self._demean:
Expand Down Expand Up @@ -489,7 +488,7 @@ def _fill_missing_em(self):
mask = np.isnan(data)

# 4. Compute mean
mu = nanmean(data, 0)
mu = np.nanmean(data, 0)

# 5. Replace missing with mean
projection = np.ones((self._nobs, 1)) * mu
Expand Down
5 changes: 2 additions & 3 deletions statsmodels/multivariate/tests/test_pca.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

from statsmodels.multivariate.pca import PCA
from statsmodels.multivariate.tests.results.datamlw import data, princomp1, princomp2
from statsmodels.compat.numpy import nanmean

DECIMAL_5 = .00001
WIN32 = os.name == 'nt' and sys.maxsize < 2**33
Expand Down Expand Up @@ -307,9 +306,9 @@ def test_replace_missing(self):

pc = PCA(x, ncomp=3, missing='fill-em')
missing = np.isnan(x)
mu = nanmean(x, axis=0)
mu = np.nanmean(x, axis=0)
errors = x - mu
sigma = np.sqrt(nanmean(errors ** 2, axis=0))
sigma = np.sqrt(np.nanmean(errors ** 2, axis=0))
x_std = errors / sigma
x_std[missing] = 0.0
last = x_std[missing]
Expand Down

0 comments on commit 6cb6d49

Please sign in to comment.