Skip to content

Commit a99c3bd

Browse files
committed
fix: replace np.nan checks with pd.isna for better NaN handling
1 parent cf93e52 commit a99c3bd

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

src/biopsykit/signals/icg/event_extraction/_b_point_miljkovic2022.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def extract(
107107
# Get the C-Point location at the current heartbeat id
108108
c_point = c_points[idx]
109109

110-
if c_point is np.nan:
110+
if pd.isna(c_point):
111111
b_points.loc[idx, "b_point_sample"] = np.nan
112112
b_points.loc[idx, "nan_reason"] = "c_point_nan"
113113
continue

src/biopsykit/signals/icg/event_extraction/_b_point_pale2021.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,13 @@ def extract(
118118
# Get the C-Point location at the current heartbeat id
119119
c_point = c_points[idx]
120120

121-
icg_slice = icg.iloc[data["start_sample"] : c_point]
122-
123-
if c_point is np.nan:
121+
if pd.isna(c_point):
124122
b_points.loc[idx, "b_point_sample"] = np.nan
125123
b_points.loc[idx, "nan_reason"] = "c_point_nan"
126124
continue
127125

126+
icg_slice = icg.iloc[data["start_sample"] : c_point]
127+
128128
# Calculate the search window based on the C-point location and amplitude
129129
# start of the search window is 80 ms before the C-point
130130
search_window_start = c_point - int(0.08 * sampling_rate_hz)
@@ -140,6 +140,11 @@ def extract(
140140
# B_min is the minimum of the signal in the search window
141141
b_point_min = data["start_sample"] + np.argmin(icg_slice)
142142

143+
if (search_window_end - search_window_start) <= 2:
144+
# If the search window is too small, set the B-point to the minimum of the signal in the search window
145+
b_points.loc[idx, "b_point_sample"] = b_point_min
146+
continue
147+
143148
# slice derivative to the search window
144149
icg_2nd_der_slice = icg_2nd_der[search_window_start:search_window_end]
145150

src/biopsykit/stats/stats.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,9 +1144,7 @@ def _remove_a_b(data: pd.DataFrame) -> pd.DataFrame:
11441144
return data.reorder_levels(names_new)
11451145

11461146
@staticmethod
1147-
def _format_latex_table_index(
1148-
data: pd.DataFrame, index_kws: dict[str, Any], show_a_b: bool | None = False
1149-
): # pylint:disable=too-many-branches
1147+
def _format_latex_table_index(data: pd.DataFrame, index_kws: dict[str, Any], show_a_b: bool | None = False): # pylint:disable=too-many-branches
11501148
index_italic = index_kws.get("index_italic", True)
11511149
index_level_order = index_kws.get("index_level_order")
11521150
index_value_order = index_kws.get("index_value_order")

0 commit comments

Comments
 (0)