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

DATA: update sum check #874

Merged
merged 1 commit into from
Jul 24, 2019
Merged
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
7 changes: 4 additions & 3 deletions reco_utils/dataset/split_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import pandas as pd
import numpy as np
import math

from reco_utils.common.constants import DEFAULT_ITEM_COL, DEFAULT_USER_COL

Expand Down Expand Up @@ -36,8 +37,8 @@ def process_split_ratio(ratio):
)

# normalize split ratios if they are not summed to 1
if sum(ratio) != 1.0:
ratio = [x / sum(ratio) for x in ratio]
if math.fsum(ratio) != 1.0:
ratio = [x / math.fsum(ratio) for x in ratio]

multi = True
else:
Expand Down Expand Up @@ -153,7 +154,7 @@ def split_pandas_data_with_ratios(data, ratios, seed=42, shuffle=False):
Returns:
list: List of pd.DataFrame split by the given specifications.
"""
if sum(ratios) != 1.0:
if math.fsum(ratios) != 1.0:
raise ValueError("The ratios have to sum to 1")

split_index = np.cumsum(ratios).tolist()[:-1]
Expand Down