Skip to content

Commit

Permalink
Fix numpy.nan for numpy 2.0 compatibility (#544)
Browse files Browse the repository at this point in the history
Fixes #543.
  • Loading branch information
bgyori authored Jun 20, 2024
1 parent fdb2e71 commit 9d13221
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/sssom/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ def from_sssom_dataframe(
# This is to address: A value is trying to be set on a copy of a slice from a DataFrame
if CONFIDENCE in df.columns:
df2 = df.copy()
df2[CONFIDENCE].replace(r"^\s*$", np.NaN, regex=True, inplace=True)
df2[CONFIDENCE].replace(r"^\s*$", np.nan, regex=True, inplace=True)
df = df2

mapping_set = _get_mapping_set_from_df(df=df, meta=meta)
Expand Down
6 changes: 3 additions & 3 deletions src/sssom/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ def assign_default_confidence(
ValueError("DataFrame cannot be empty to 'assign_default_confidence'.")
new_df = df.copy()
if CONFIDENCE not in new_df.columns:
new_df[CONFIDENCE] = 0.0 # np.NaN
new_df[CONFIDENCE] = 0.0 # np.nan
nan_df = pd.DataFrame(columns=new_df.columns)
else:
new_df = df[~df[CONFIDENCE].isna()]
Expand Down Expand Up @@ -655,7 +655,7 @@ def compare_dataframes(df1: pd.DataFrame, df2: pd.DataFrame) -> MappingSetDiff:
return d


def add_default_confidence(df: pd.DataFrame, confidence: float = np.NAN) -> pd.DataFrame:
def add_default_confidence(df: pd.DataFrame, confidence: float = np.nan) -> pd.DataFrame:
"""Add `confidence` column to DataFrame if absent and initializes to 0.95.
If `confidence` column already exists, only fill in the None ones by 0.95.
Expand Down Expand Up @@ -862,7 +862,7 @@ def deal_with_negation(df: pd.DataFrame) -> pd.DataFrame:
#1; #2(i) #3 and $4 are taken care of by 'filtered_merged_df' Only #2(ii) should be performed here.
"""

# Handle DataFrames with no 'confidence' column (basically adding a np.NaN to all non-numeric confidences)
# Handle DataFrames with no 'confidence' column (basically adding a np.nan to all non-numeric confidences)
confidence_in_original = CONFIDENCE in df.columns
df, nan_df = assign_default_confidence(df)

Expand Down

0 comments on commit 9d13221

Please sign in to comment.