eyurtsev / FlowCytometryTools

A python package for visualization and analysis of high-throughput flow cytometry data
https://eyurtsev.github.io/FlowCytometryTools/
MIT License
113 stars 46 forks source link

[core] Fix TypeError on FCMeasurement.subset() with Python 3.5 #19

Closed douglas-watson closed 6 years ago

douglas-watson commented 6 years ago

Hi,

@elianeroosli found a bug when calling subset() with Python 3.5. She got the following exception:

Traceback (most recent call last):
  File "testcase.py", line 4, in <module>
    d.subsample(0.5)
  File "/home/dwatson/code/FlowCytometryTools/FlowCytometryTools/core/containers.py", line 334, in subsample
    newdata = data.loc[sample(data.index, key)]  # Use loc not iloc here!!
  File "/home/dwatson/code/FlowCytometryTools/env/lib/python3.5/random.py", line 311, in sample
    raise TypeError("Population must be a sequence or set.  For dicts, use list(d).")
TypeError: Population must be a sequence or set.  For dicts, use list(d).

My pull request fixes the bug, at least for python 3.5.

Minimum code to reproduce the error (run from the root directory of this repo):

import FlowCytometryTools as fct  

d = fct.FCMeasurement('test', 'FlowCytometryTools/tests/data/FlowCytometers/HTS_BD_LSR-II/HTS_BD_LSR_II_Mixed_Specimen_001_D6_D06.fcs')
d.subsample(0.5)

Cheers! Douglas

eyurtsev commented 6 years ago

The test failures have nothing to do with your diff -- I forgot to fix up the tests after making a change in the fcsparser

Merging as is! Diff is much appreciated!