Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion alpharaw/ms_data_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ def add_column_in_spec_df_by_spec_idxes(
na_value=np.nan,
):
self.spectrum_df.loc[spec_idxes, column_name] = values
self.spectrum_df[column_name].fillna(na_value, inplace=True)
self.spectrum_df[column_name] = self.spectrum_df[column_name].fillna(na_value)
self.spectrum_df[column_name] = self.spectrum_df[column_name].astype(dtype)

def add_column_in_df_by_scan_num(
Expand Down
23 changes: 23 additions & 0 deletions tests/unit/test_ms_data_base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import warnings

import numpy as np

from alpharaw.ms_data_base import MSData_Base


def test_add_column_in_spec_df_avoids_chained_assignment_warning():
ms_data = MSData_Base()
ms_data.create_spectrum_df(3)

with warnings.catch_warnings():
warnings.simplefilter("error", FutureWarning)
ms_data.add_column_in_spec_df_by_spec_idxes(
"ms_level",
np.array([2, 3]),
np.array([0, 2]),
dtype=np.int8,
na_value=1,
)

np.testing.assert_array_equal(ms_data.spectrum_df["ms_level"], [2, 1, 3])
assert ms_data.spectrum_df["ms_level"].dtype == np.int8