KrishnaswamyLab / scprep

A collection of scripts and tools for loading, processing, and handling single cell data.
MIT License
72 stars 21 forks source link

`scprep.plot.scatter2d` doesn't handle a single point #97

Closed scottgigante closed 4 years ago

scottgigante commented 4 years ago

Describe the bug scprep.plot.scatter2d doesn't handle a single point

To Reproduce

import scprep
scprep.plot.scatter2d([1, 2])

Expected behavior Should behave the same as

import scprep
scprep.plot.scatter2d([[1, 2]])

Actual behavior

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
~/.local/lib/python3.8/site-packages/scprep/select.py in _get_column_length(data)
     39     try:
---> 40         return data.shape[1]
     41     except (IndexError, AttributeError):

IndexError: tuple index out of range

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
<ipython-input-21-51af89786b54> in <module>
----> 1 scprep.plot.scatter2d([1, 2])

</usr/lib/python3.8/site-packages/decorator.py:decorator-gen-142> in scatter2d(data, c, cmap, cmap_scale, s, mask, discrete, ax, legend, colorbar, shuffle, figsize, ticks, xticks, yticks, ticklabels, xticklabels, yticklabels, label_prefix, xlabel, ylabel, title, fontsize, legend_title, legend_loc, legend_anchor, filename, dpi, **plot_kwargs)

~/.local/lib/python3.8/site-packages/scprep/utils.py in _with_pkg(fun, pkg, min_version, *args, **kwargs)
     81         check_version(pkg, min_version=min_version)
     82         __imported_pkgs.add((pkg, min_version))
---> 83     return fun(*args, **kwargs)
     84 
     85 

~/.local/lib/python3.8/site-packages/scprep/plot/scatter.py in scatter2d(data, c, cmap, cmap_scale, s, mask, discrete, ax, legend, colorbar, shuffle, figsize, ticks, xticks, yticks, ticklabels, xticklabels, yticklabels, label_prefix, xlabel, ylabel, title, fontsize, legend_title, legend_loc, legend_anchor, filename, dpi, **plot_kwargs)
    943         data = utils.toarray(data)
    944     return scatter(
--> 945         x=select.select_cols(data, idx=0),
    946         y=select.select_cols(data, idx=1),
    947         c=c,

~/.local/lib/python3.8/site-packages/scprep/select.py in select_cols(data, idx, starts_with, ends_with, exact_word, regex, *extra_data)
    441             idx = utils.toarray(idx)
    442         data = data[:, idx]
--> 443     if _get_column_length(data) == 0:
    444         warnings.warn("Selecting 0 columns.", UserWarning)
    445     elif isinstance(data, pd.DataFrame):

~/.local/lib/python3.8/site-packages/scprep/select.py in _get_column_length(data)
     40         return data.shape[1]
     41     except (IndexError, AttributeError):
---> 42         return len(data)
     43 
     44 

TypeError: object of type 'numpy.int64' has no len()

scprep version 1.0.4a0

Output of pd.show_versions()

``` INSTALLED VERSIONS ------------------ commit : None python : 3.8.1.final.0 python-bits : 64 OS : Linux OS-release : 5.4.7-arch1-1 machine : x86_64 processor : byteorder : little LC_ALL : None LANG : en_US.UTF-8 LOCALE : en_US.UTF-8 pandas : 0.25.3 numpy : 1.18.0 pytz : 2019.3 dateutil : 2.8.1 pip : 19.2.3 setuptools : 42.0.2 Cython : 0.29.14 pytest : 5.3.2 hypothesis : 4.54.2 sphinx : 2.3.1 blosc : None feather : None xlsxwriter : None lxml.etree : 4.4.2 html5lib : 1.0.1 pymysql : None psycopg2 : None jinja2 : 2.10.3 IPython : 7.11.1 pandas_datareader: 0.8.1 bs4 : None bottleneck : 1.3.1 fastparquet : None gcsfs : None lxml.etree : 4.4.2 matplotlib : 3.0.3 numexpr : 2.7.0 odfpy : None openpyxl : 3.0.1 pandas_gbq : None pyarrow : None pytables : None s3fs : None scipy : 1.4.1 sqlalchemy : 1.3.12 tables : 3.6.1 xarray : None xlrd : 1.2.0 xlwt : 1.3.0 xlsxwriter : None ```