Skip to content

Commit

Permalink
Replace np.NaN with np.nan
Browse files Browse the repository at this point in the history
  • Loading branch information
moeyensj committed Oct 29, 2024
1 parent f8c26ac commit c3a40a5
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
22 changes: 11 additions & 11 deletions src/difi/difi.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def analyzeLinkages(
"object_id": objects.index.values,
# "class" : ["None" for i in range(len(objects))],
"num_obs": np.zeros(len(objects), dtype=int),
"findable": [np.NaN for i in range(len(objects))],
"findable": [np.nan for i in range(len(objects))],
}
)
all_objects["object_id"] = all_objects["object_id"].astype(str)
Expand All @@ -262,7 +262,7 @@ def analyzeLinkages(
"No findable column found in all_objects. Completeness\n" "statistics can not be calculated."
)
warnings.warn(warn, UserWarning)
all_objects.loc[:, "findable"] = np.NaN
all_objects.loc[:, "findable"] = np.nan
findable_present = False
_checkColumnTypesEqual(all_objects, observations, ["object_id"])

Expand Down Expand Up @@ -614,7 +614,7 @@ def analyzeLinkages(

# Calculate completeness
if findable == 0:
completeness = np.NaN
completeness = np.nan
else:
completeness = 100.0 * findable_found / findable
summary["completeness"].append(completeness)
Expand All @@ -638,12 +638,12 @@ def analyzeLinkages(
summary["not_findable_missed"].append(not_findable_missed)

else:
summary["completeness"].append(np.NaN)
summary["findable"].append(np.NaN)
summary["findable_found"].append(np.NaN)
summary["findable_missed"].append(np.NaN)
summary["not_findable_found"].append(np.NaN)
summary["not_findable_missed"].append(np.NaN)
summary["completeness"].append(np.nan)
summary["findable"].append(np.nan)
summary["findable_found"].append(np.nan)
summary["findable_missed"].append(np.nan)
summary["not_findable_found"].append(np.nan)
summary["not_findable_missed"].append(np.nan)

# Calculate number of linkage types that contain observations of this class
for linkage_type in [
Expand Down Expand Up @@ -702,8 +702,8 @@ def analyzeLinkages(
].nunique()
)

all_linkages.loc[all_linkages["mixed"] == 1, "object_id"] = np.NaN
all_linkages.loc[all_linkages["mixed"] == 1, "contamination_percentage_in_linkages"] = np.NaN
all_linkages.loc[all_linkages["mixed"] == 1, "object_id"] = np.nan
all_linkages.loc[all_linkages["mixed"] == 1, "contamination_percentage_in_linkages"] = np.nan
all_linkages["object_id"] = all_linkages["object_id"].astype(str)

# Drop all duplicate linkage_id entries which has the effect of
Expand Down
10 changes: 5 additions & 5 deletions src/difi/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,11 +680,11 @@ def _run_object_worker(
}
else:
findable = {
"window_id": np.NaN,
"object_id": np.NaN,
"findable": np.NaN,
"discovery_opportunities": np.NaN,
"obs_ids": np.NaN,
"window_id": np.nan,
"object_id": np.nan,
"findable": np.nan,
"discovery_opportunities": np.nan,
"obs_ids": np.nan,
}

findable_dicts.append(findable)
Expand Down
2 changes: 1 addition & 1 deletion src/difi/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def test_linkages(test_observations):
all_linkages_expected["pure_complete"].append(False)
all_linkages_expected["partial"].append(False)
all_linkages_expected["mixed"].append(True)
all_linkages_expected["contamination_percentage"].append(np.NaN)
all_linkages_expected["contamination_percentage"].append(np.nan)
all_linkages_expected["found_pure"].append(False)
all_linkages_expected["found_partial"].append(False)
all_linkages_expected["found"].append(False)
Expand Down
4 changes: 2 additions & 2 deletions src/difi/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def test__checkColumnTypesEqual():


def test__percentHandler():
# If the denominator is 0, then _percentHandler should return np.NaN
# If the denominator is 0, then _percentHandler should return np.nan
number = np.random.choice(np.arange(0, 10000))
total_number = 0
assert np.isnan(_percentHandler(number, total_number))
Expand Down Expand Up @@ -228,7 +228,7 @@ def test__classHandler_warnings():
# Remove the orange class from classes dict
classes_dict_ = copy.deepcopy(classes_dict)
classes_dict_.pop("orange")
observations.loc[observations["class"].isin(["orange"]), "class"] = np.NaN
observations.loc[observations["class"].isin(["orange"]), "class"] = np.nan

# Test for UserWarning when not all truths have an assigned class
with pytest.warns(UserWarning):
Expand Down
4 changes: 2 additions & 2 deletions src/difi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def _classHandler(
def _percentHandler(number: float, number_total: float) -> float:
"""
Returns a percentage value of number / number_total. Returns
np.NaN is number total is zero.
np.nan is number total is zero.
Parameters
----------
Expand All @@ -206,7 +206,7 @@ def _percentHandler(number: float, number_total: float) -> float:
percent : float
"""
if number_total == 0:
percent_total = np.NaN
percent_total = np.nan
else:
percent_total = 100.0 * number / number_total

Expand Down

0 comments on commit c3a40a5

Please sign in to comment.