Skip to content

IndexError: single positional indexer is out-of-bounds when using cnp.pl.histogram() #21

@liezeltamon

Description

@liezeltamon

Hi @TarikExner,

Any idea why I am getting the error below when using cnp.pl.histogram(). I'm trying to reproduce the error using the vignette data but I'm getting another error in the calculation part when I set everything to "other" to mimic my case where I don't have any reference. The function works okay if I just run on the vignette data as it is so it might be related to not having a reference?

I'll let you know when I've reproduced the error using the vignette data but just sharing now in case it is something familiar. Thank you!

file_name = "SLE_inactive_15.fcs"
fig = cnp.pl.histogram(
    cn,
    file_name=file_name, #files[3],
    x_channel="Bi209Di",
    x_scale="linear",
    #display_reference=True,
    grid="channels",
    #channels=markers_for_clustering,
    figsize=(20, 20),
    show=False,
    return_fig=True,
)
print(f"Plotting histograms for {file_name}...")

Error:

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
File /well/immune-rep/users/yfg436/git/sle/code/cytof/integrate/cytonorm.py:2
      1 print(f"Plotting histograms for {file_name}...")
----> 2 fig = cnp.pl.histogram(
      3     cn,
      4     file_name=file_name, #files[3],
      5     x_channel="Nd142Di",
      6     x_scale="linear",
      7     #display_reference=True,
      8     grid="channels",
      9     #channels=markers_for_clustering,
     10     figsize=(20, 20),
     11     show=False,
     12     return_fig=True,
     13 )

File /gpfs3/well/immune-rep/users/yfg436/mamba_installation/conda/envs/cytonormpy-env/lib/python3.10/site-packages/cytonormpy/_plotting/_histogram.py:139, in histogram(cnp, file_name, x_channel, x_scale, y_scale, xlim, ylim, linthresh, subsample, display_reference, grid, grid_n_cols, channels, vary_textures, figsize, ax, return_fig, show, save, **kwargs)
    136 if grid == "channels" and file_name is None:
    137     raise ValueError("A Grid by channels needs a file_name")
--> 139 data = _prepare_data(cnp, file_name, display_reference, channels, subsample=subsample)
    141 hues = data.index.get_level_values("origin").unique().sort_values()
    143 dash_styles = DASH_STYLES

File /gpfs3/well/immune-rep/users/yfg436/mamba_installation/conda/envs/cytonormpy-env/lib/python3.10/site-packages/cytonormpy/_plotting/_scatter.py:186, in _prepare_data(cnp, file_name, display_reference, channels, subsample)
    181 normalized_df = cnp._normalize_file(
    182     df=original_df.copy(), batch=cnp._datahandler.metadata.get_batch(file_name)
    183 )
    185 if display_reference is True:
--> 186     ref_df = cnp._datahandler.get_corresponding_ref_dataframe(file_name)
    187     ref_df["origin"] = "reference"
    188     ref_df = ref_df.set_index("origin", append=True, drop=True)

File /gpfs3/well/immune-rep/users/yfg436/mamba_installation/conda/envs/cytonormpy-env/lib/python3.10/site-packages/cytonormpy/_dataset/_dataset.py:82, in DataHandler.get_corresponding_ref_dataframe(self, file_name)
     80 def get_corresponding_ref_dataframe(self, file_name: str) -> pd.DataFrame:
     81     """Returns the data of the corresponding reference for the indicated file name."""
---> 82     corresponding_reference_file = self.metadata.get_corresponding_reference_file(file_name)
     83     return self.get_dataframe(file_name=corresponding_reference_file)

File /gpfs3/well/immune-rep/users/yfg436/mamba_installation/conda/envs/cytonormpy-env/lib/python3.10/site-packages/cytonormpy/_dataset/_metadata.py:107, in Metadata.get_corresponding_reference_file(self, file_name)
    105 """Returns the corresponding reference file of a file."""
    106 batch = self.get_batch(file_name)
--> 107 return self.metadata.loc[
    108     (self.metadata[self.batch_column] == batch)
    109     & (self.metadata[self.reference_column] == self.reference_value),
    110     self.sample_identifier_column,
    111 ].iloc[0]

File /gpfs3/well/immune-rep/users/yfg436/mamba_installation/conda/envs/cytonormpy-env/lib/python3.10/site-packages/pandas/core/indexing.py:1192, in _LocationIndexer.__getitem__(self, key)
   1190 maybe_callable = com.apply_if_callable(key, self.obj)
   1191 maybe_callable = self._check_deprecated_callable_usage(key, maybe_callable)
-> 1192 return self._getitem_axis(maybe_callable, axis=axis)

File /gpfs3/well/immune-rep/users/yfg436/mamba_installation/conda/envs/cytonormpy-env/lib/python3.10/site-packages/pandas/core/indexing.py:1753, in _iLocIndexer._getitem_axis(self, key, axis)
   1750     raise TypeError("Cannot index by location index with a non-integer key")
   1752 # validate the location
-> 1753 self._validate_integer(key, axis)
   1755 return self.obj._ixs(key, axis=axis)

File /gpfs3/well/immune-rep/users/yfg436/mamba_installation/conda/envs/cytonormpy-env/lib/python3.10/site-packages/pandas/core/indexing.py:1686, in _iLocIndexer._validate_integer(self, key, axis)
   1684 len_axis = len(self.obj._get_axis(axis))
   1685 if key >= len_axis or key < -len_axis:
-> 1686     raise IndexError("single positional indexer is out-of-bounds")

IndexError: single positional indexer is out-of-bounds

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions