Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Violin plots fail when empty array is included among violin data #342

Open
JS3xton opened this issue Oct 27, 2020 · 2 comments · Fixed by #348
Open

Violin plots fail when empty array is included among violin data #342

JS3xton opened this issue Oct 27, 2020 · 2 comments · Fixed by #348
Labels

Comments

@JS3xton
Copy link
Contributor

JS3xton commented Oct 27, 2020

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

>>> FlowCal.plot.violin(data=[[1,2,3],[],[4,5,6]])

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 1753, in violin
  File "<__array_function__ internals>", line 5, in amin
  File "C:\Users\sexto\.conda\envs\py3_anaconda2020.07_fc_JS3xton_bc98686\lib\site-packages\numpy\core\fromnumeric.py", line 2792, in amin
    return _wrapreduction(a, np.minimum, 'min', axis, None, out,
  File "C:\Users\sexto\.conda\envs\py3_anaconda2020.07_fc_JS3xton_bc98686\lib\site-packages\numpy\core\fromnumeric.py", line 90, in _wrapreduction
    return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
ValueError: zero-size array to reduction operation minimum which has no identity

The error comes from using np.min() to calculate defaults limits for the data axis:

        data_min = np.inf
        data_max = -np.inf
        for idx in range(data_length):
            violin_data = np.array(data[idx], dtype=np.float).flat
            violin_min = np.min(violin_data)  # <-- fails here
            violin_max = np.max(violin_data)
            if violin_min < data_min:
                data_min = violin_min
            if violin_max > data_max:
                data_max = violin_max
        data_lim = (data_min, data_max)

np.min() fails when called on an empty array.

@JS3xton
Copy link
Contributor Author

JS3xton commented Jan 26, 2021

Fixed in FlowCal v1.3.0.

@JS3xton JS3xton closed this as completed Jan 26, 2021
@JS3xton
Copy link
Contributor Author

JS3xton commented Mar 3, 2023

FlowCal.plot.violin(data=[[1,2,3],[],[4,5,6]]) 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 271, in __init__
    if d.ndim > 1:
AttributeError: 'list' object has no attribute 'ndim'

@JS3xton JS3xton reopened this Mar 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant