taborlab / FlowCal

Python Flow Cytometry Calibration Library
MIT License
48 stars 23 forks source link

Violin plots fail when called with empty array #343

Open JS3xton opened 3 years ago

JS3xton commented 3 years ago

The following code fails using commit bc98686677dde12dd6ba6987b8d753fdb7692c5c (a few commits upstream of when plot-violin was merged into develop):

>>> FlowCal.plot.violin(data=[])

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\sexto\.conda\envs\py3_anaconda2020.07_fc_JS3xton_bc98686\lib\site-packages\flowcal-1.2.2-py3.8.egg\FlowCal\plot.py", line 1690, in violin
StopIteration

The error occurs when next() is called on an empty iterator when trying to understand data:

    # understand `data`
    if channel is None:
        # assume 1D sequence or sequence of 1D sequences
        try:
            first_element = next(iter(data))  # <-- fails here
        except TypeError:
            msg  = "`data` should be 1D array or list of 1D arrays."
            msg += " Specify `channel` to use ND array or list of ND"
            msg += " arrays."
            raise TypeError(msg)

        # promote singleton if necessary
        try:
            iter(first_element)  # success => sequence of 1D sequences
            data_length = len(data)
        except TypeError:
            data = [data]
            data_length = 1
JS3xton commented 3 years ago

Fixed in FlowCal v1.3.0.

JS3xton commented 1 year ago

FlowCal.plot.violin(data=[]) still fails in v1.3.0 with the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/jsexton/Downloads/FlowCal-master/FlowCal/plot.py", line 1810, in violin
    t = _LogicleTransform(data=data, channel=channel)
  File "/home/jsexton/Downloads/FlowCal-master/FlowCal/plot.py", line 315, in __init__
    raise ValueError("T should be positive")
ValueError: T should be positive