Skip to content

Commit

Permalink
[TST, REF] Address pandas SettingWithCopyWarnings (#534)
Browse files Browse the repository at this point in the history
* Address warning in ImagesToCoordinates.

* Address in validate_images_df.

* Raise exception on warning in tests.
  • Loading branch information
tsalo authored Jul 1, 2021
1 parent 5a5d5e5 commit f69f396
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions nimare/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import nibabel as nib
import numpy as np
import pandas as pd
import pytest
from nilearn.image import resample_img

Expand All @@ -12,6 +13,8 @@

from ..utils import get_resource_path

pd.options.mode.chained_assignment = "raise"


@pytest.fixture(scope="session")
def testdata_ibma(tmp_path_factory):
Expand Down
2 changes: 1 addition & 1 deletion nimare/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ def transform(self, dataset):

# specify original coordinates
original_ids = set(old_coordinates_df["id"])
metadata[metadata["id"].isin(original_ids)]["coordinate_source"] = "original"
metadata.loc[metadata["id"].isin(original_ids), "coordinate_source"] = "original"

# ensure z_stat is treated as float
if "z_stat" in coordinates_df.columns:
Expand Down
4 changes: 3 additions & 1 deletion nimare/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,12 @@ def validate_images_df(image_df):
if not shared_path.endswith(op.sep):
shared_path = op.dirname(shared_path) + op.sep
LGR.info("Shared path detected: '{0}'".format(shared_path))
image_df_out = image_df.copy() # To avoid SettingWithCopyWarning
for abs_col in abs_cols:
image_df[abs_col + "__relative"] = image_df[abs_col].apply(
image_df_out[abs_col + "__relative"] = image_df[abs_col].apply(
lambda x: x.split(shared_path)[1] if isinstance(x, str) else x
)
image_df = image_df_out
return image_df


Expand Down

0 comments on commit f69f396

Please sign in to comment.