def _nobs_raw(self): if self._is_rolling: window = self._window else: # expanding case window = len(self._index) result = Series(self._time_obs_count).rolling(window, min_periods=1).sum().values return result.astype(int)
def _nobs_raw(self): if self._is_rolling: window = self._window else: # expanding case window = len(self._index) result = Series(self._time_obs_count).rolling( window, min_periods=1).sum().values return result.astype(int)
def test_value_counts_normalized(self): # GH12558 s = Series([1, 2, np.nan, np.nan, np.nan]) dtypes = (np.float64, np.object, 'M8[ns]') for t in dtypes: s_typed = s.astype(t) result = s_typed.value_counts(normalize=True, dropna=False) expected = Series([0.6, 0.2, 0.2], index=Series([np.nan, 2.0, 1.0], dtype=t)) tm.assert_series_equal(result, expected) result = s_typed.value_counts(normalize=True, dropna=True) expected = Series([0.5, 0.5], index=Series([2.0, 1.0], dtype=t)) tm.assert_series_equal(result, expected)
def test_value_counts_normalized(self): # GH12558 s = Series([1, 2, np.nan, np.nan, np.nan]) dtypes = (np.float64, np.object, 'M8[ns]') for t in dtypes: s_typed = s.astype(t) result = s_typed.value_counts(normalize=True, dropna=False) expected = Series([0.6, 0.2, 0.2], index=Series([np.nan, 2.0, 1.0], dtype=t)) tm.assert_series_equal(result, expected) result = s_typed.value_counts(normalize=True, dropna=True) expected = Series([0.5, 0.5], index=Series([2.0, 1.0], dtype=t)) tm.assert_series_equal(result, expected)
def _window_time_obs(self): window_obs = Series(self._time_obs_count > 0).rolling(self._window, min_periods=1).sum().values window_obs[np.isnan(window_obs)] = 0 return window_obs.astype(int)