From c3a40a56918c4942adcf9d77c70b6fd905cac996 Mon Sep 17 00:00:00 2001 From: Joachim Moeyens Date: Tue, 29 Oct 2024 14:19:24 -0700 Subject: [PATCH] Replace np.NaN with np.nan --- src/difi/difi.py | 22 +++++++++++----------- src/difi/metrics.py | 10 +++++----- src/difi/tests/conftest.py | 2 +- src/difi/tests/test_utils.py | 4 ++-- src/difi/utils.py | 4 ++-- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/difi/difi.py b/src/difi/difi.py index bee3681..a476bf8 100644 --- a/src/difi/difi.py +++ b/src/difi/difi.py @@ -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) @@ -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"]) @@ -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) @@ -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 [ @@ -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 diff --git a/src/difi/metrics.py b/src/difi/metrics.py index 6649b1f..85d63ca 100644 --- a/src/difi/metrics.py +++ b/src/difi/metrics.py @@ -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) diff --git a/src/difi/tests/conftest.py b/src/difi/tests/conftest.py index dd48d9a..d9ee680 100644 --- a/src/difi/tests/conftest.py +++ b/src/difi/tests/conftest.py @@ -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) diff --git a/src/difi/tests/test_utils.py b/src/difi/tests/test_utils.py index df3f43e..e5a4b5a 100644 --- a/src/difi/tests/test_utils.py +++ b/src/difi/tests/test_utils.py @@ -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)) @@ -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): diff --git a/src/difi/utils.py b/src/difi/utils.py index 53beebb..3426bdd 100644 --- a/src/difi/utils.py +++ b/src/difi/utils.py @@ -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 ---------- @@ -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