def test_all_any_params(self): # Check skipna, with implicit 'object' dtype. s1 = Series([np.nan, True]) s2 = Series([np.nan, False]) assert s1.all(skipna=False) # nan && True => True assert s1.all(skipna=True) assert np.isnan(s2.any(skipna=False)) # nan || False => nan assert not s2.any(skipna=True) # Check level. s = pd.Series([False, False, True, True, False, True], index=[0, 0, 1, 1, 2, 2]) tm.assert_series_equal(s.all(level=0), Series([False, True, False])) tm.assert_series_equal(s.any(level=0), Series([False, True, True])) # bool_only is not implemented with level option. with pytest.raises(NotImplementedError): s.any(bool_only=True, level=0) with pytest.raises(NotImplementedError): s.all(bool_only=True, level=0) # bool_only is not implemented alone. with pytest.raises(NotImplementedError): s.any(bool_only=True) with pytest.raises(NotImplementedError): s.all(bool_only=True)
def test_all_any_params(self): # Check skipna, with implicit 'object' dtype. s1 = Series([np.nan, True]) s2 = Series([np.nan, False]) assert s1.all(skipna=False) # nan && True => True assert s1.all(skipna=True) assert np.isnan(s2.any(skipna=False)) # nan || False => nan assert not s2.any(skipna=True) # Check level. s = pd.Series([False, False, True, True, False, True], index=[0, 0, 1, 1, 2, 2]) tm.assert_series_equal(s.all(level=0), Series([False, True, False])) tm.assert_series_equal(s.any(level=0), Series([False, True, True])) # bool_only is not implemented with level option. with pytest.raises(NotImplementedError): s.any(bool_only=True, level=0) with pytest.raises(NotImplementedError): s.all(bool_only=True, level=0) # bool_only is not implemented alone. with pytest.raises(NotImplementedError): s.any(bool_only=True,) with pytest.raises(NotImplementedError): s.all(bool_only=True)
def test_all_any_boolean(self): # Check skipna, with boolean type s1 = Series([pd.NA, True], dtype="boolean") s2 = Series([pd.NA, False], dtype="boolean") assert s1.all(skipna=False) is pd.NA # NA && True => NA assert s1.all(skipna=True) assert s2.any(skipna=False) is pd.NA # NA || False => NA assert not s2.any(skipna=True) # GH-33253: all True / all False values buggy with skipna=False s3 = Series([True, True], dtype="boolean") s4 = Series([False, False], dtype="boolean") assert s3.all(skipna=False) assert not s4.any(skipna=False) # Check level TODO(GH-33449) result should also be boolean s = Series( [False, False, True, True, False, True], index=[0, 0, 1, 1, 2, 2], dtype="boolean", ) with tm.assert_produces_warning(FutureWarning): tm.assert_series_equal(s.all(level=0), Series([False, True, False])) with tm.assert_produces_warning(FutureWarning): tm.assert_series_equal(s.any(level=0), Series([False, True, True]))
class All: params = [[10**3, 10**6], ["fast", "slow"]] param_names = ["N", "case"] def setup(self, N, case): val = case != "fast" self.s = Series([val] * N) def time_all(self, N, case): self.s.all()
class All(object): params = [[10**3, 10**6], ['fast', 'slow']] param_names = ['N', 'case'] def setup(self, N, case): val = case != 'fast' self.s = Series([val] * N) def time_all(self, N, case): self.s.all()
def test_all_any_params(self): # Check skipna, with implicit 'object' dtype. s1 = Series([np.nan, True]) s2 = Series([np.nan, False]) assert s1.all(skipna=False) # nan && True => True assert s1.all(skipna=True) assert s2.any(skipna=False) assert not s2.any(skipna=True) # Check level. s = Series([False, False, True, True, False, True], index=[0, 0, 1, 1, 2, 2]) with tm.assert_produces_warning(FutureWarning): tm.assert_series_equal(s.all(level=0), Series([False, True, False])) with tm.assert_produces_warning(FutureWarning): tm.assert_series_equal(s.any(level=0), Series([False, True, True])) msg = "Option bool_only is not implemented with option level" with pytest.raises(NotImplementedError, match=msg): with tm.assert_produces_warning(FutureWarning): s.any(bool_only=True, level=0) with pytest.raises(NotImplementedError, match=msg): with tm.assert_produces_warning(FutureWarning): s.all(bool_only=True, level=0) # GH#38810 bool_only is not implemented alone. msg = "Series.any does not implement bool_only" with pytest.raises(NotImplementedError, match=msg): s.any(bool_only=True) msg = "Series.all does not implement bool_only." with pytest.raises(NotImplementedError, match=msg): s.all(bool_only=True)
def test_all_any_params(self): # Check skipna, with implicit 'object' dtype. s1 = Series([np.nan, True]) s2 = Series([np.nan, False]) assert s1.all(skipna=False) # nan && True => True assert s1.all(skipna=True) assert np.isnan(s2.any(skipna=False)) # nan || False => nan assert not s2.any(skipna=True) # Check level. s = Series([False, False, True, True, False, True], index=[0, 0, 1, 1, 2, 2]) tm.assert_series_equal(s.all(level=0), Series([False, True, False])) tm.assert_series_equal(s.any(level=0), Series([False, True, True])) msg = "Option bool_only is not implemented with option level" with pytest.raises(NotImplementedError, match=msg): s.any(bool_only=True, level=0) with pytest.raises(NotImplementedError, match=msg): s.all(bool_only=True, level=0) # bool_only is not implemented alone. # TODO GH38810 change this error message to: # "Series.any does not implement bool_only" msg = "Series.any does not implement numeric_only" with pytest.raises(NotImplementedError, match=msg): s.any(bool_only=True) msg = "Series.all does not implement numeric_only." with pytest.raises(NotImplementedError, match=msg): s.all(bool_only=True)
def test_any_all_datetimelike(self): # GH#38723 these may not be the desired long-term behavior (GH#34479) # but in the interim should be internally consistent dta = date_range("1995-01-02", periods=3)._data ser = Series(dta) df = DataFrame(ser) assert dta.all() assert dta.any() assert ser.all() assert ser.any() assert df.any().all() assert df.all().all() dta = dta.tz_localize("UTC") ser = Series(dta) df = DataFrame(ser) assert dta.all() assert dta.any() assert ser.all() assert ser.any() assert df.any().all() assert df.all().all() tda = dta - dta[0] ser = Series(tda) df = DataFrame(ser) assert tda.any() assert not tda.all() assert ser.any() assert not ser.all() assert df.any().all() assert not df.all().any()
def _gen_tree(self, X: pd.DataFrame, y: pd.Series, parent_col='root', parent_val=''): # noqa '''funcao recursiva: retorna o no da arvore de decisao e suas ramificacoes''' # noqa # se todos forem da mesma classe retorna nó folha if y.all() or (~y).all(): return Node(parent_col, val=parent_val, target=y.all()) # noqa curr_entropy = self._entropy(len(y[y]) / len(y), len(y[~y]) / len(y)) chosen_col, _ = sorted(self._all_info_gain(X, y, curr_entropy), key=lambda x: x[1], reverse=True)[0] children = [ self._gen_tree(X[X[chosen_col] == val], y[X[chosen_col] == val], chosen_col, val) for val in pd.unique(X[chosen_col]) ] return Node(parent_col, children=children, val=parent_val, target='')
def f(series: pd.Series) -> bool: result = tester(series) return False if result is None else series.all()
def test_fill_vk_age(data: pd.DataFrame, expected: pd.Series): """ Test csv_connect.fill_vK_age function """ data_filled = csv_connect.fill_vk_age(data) assert data_filled['VK Age'].all() == expected.all()