Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests warnings #1628

Merged
merged 4 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion river/bandit/bayes_ucb.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def compute_index(self, arm_id):
"""the p-th quantile of the beta distribution for the arm"""
p = 1 - 1 / (self._n + 1)
posterior = self._posteriors[arm_id]
return scipy.special.btdtri(posterior.alpha, posterior.beta, p)
return scipy.special.betaincinv(posterior.alpha, posterior.beta, p)

def update(self, arm_id, *reward_args, **reward_kwargs):
"""Rewrite update function"""
Expand Down
6 changes: 3 additions & 3 deletions river/covariance/test_emp.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def test_covariance_update_sampled():
def test_covariance_update_many(ddof):
cov = covariance.EmpiricalCovariance(ddof=ddof)
p = 5
X_all = pd.DataFrame(columns=range(p))
X_all = None

for _ in range(p):
n = np.random.randint(1, 31)
Expand Down Expand Up @@ -123,7 +123,7 @@ def test_covariance_update_many(ddof):
def test_covariance_update_many_shuffled(ddof):
cov = covariance.EmpiricalCovariance(ddof=ddof)
p = 5
X_all = pd.DataFrame(columns=range(p))
X_all = None

for _ in range(p):
n = np.random.randint(5, 31)
Expand All @@ -143,7 +143,7 @@ def test_covariance_update_many_sampled():
ddof = 1
cov = covariance.EmpiricalCovariance(ddof=ddof)
p = 5
X_all = pd.DataFrame(columns=range(p))
X_all = None

for _ in range(p):
n = np.random.randint(5, 31)
Expand Down
10 changes: 8 additions & 2 deletions river/naive_bayes/bernoulli.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,18 +252,24 @@ def joint_log_likelihood_many(self, X: pd.DataFrame) -> pd.DataFrame:
unknown = [x for x in X.columns if x not in self.feature_counts]
missing = [x for x in self.feature_counts if x not in X.columns]

is_sparse = hasattr(X, "sparse")

if unknown:
X = X.drop(unknown, axis="columns")

if missing:
X[missing] = False
X[missing] = 0
if is_sparse:
# The new values need to be converted to preserve the sparseness of the dataframe.
# Input values can be intergers or floats, converting all to float preserves the behaviour without the need for complex conversion logic.
X = X.astype(pd.SparseDtype(float, 0.0))

index, columns = X.index, X.columns

if not self.class_counts or not self.feature_counts:
return pd.DataFrame(index=index)

if hasattr(X, "sparse"):
if is_sparse:
X = sparse.csr_matrix(X.sparse.to_coo())
X.data = X.data > self.true_threshold
else:
Expand Down
2 changes: 1 addition & 1 deletion river/utils/test_rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ def test_issue_1343():

"""
rmean = utils.TimeRolling(proba.MultivariateGaussian(), period=dt.timedelta(microseconds=1))
t = dt.datetime.utcnow()
t = dt.datetime.now()
rmean.update({"a": 0}, t=t)
rmean.update({"a": 1}, t=t)
Loading