Skip to content

Commit

Permalink
Merge pull request #116 from KrishnaswamyLab/dev
Browse files Browse the repository at this point in the history
scprep 1.0.12
  • Loading branch information
scottgigante committed Jan 20, 2021
2 parents a023094 + e61b368 commit c0a4845
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
if: runner.os == 'Linux'
run: |
sudo apt-get update -qq
sudo apt-get install -y libhdf5-dev libhdf5-serial-dev pandoc gfortran libblas-dev liblapack-dev libedit-dev llvm-dev libcurl4-openssl-dev ffmpeg
sudo apt-get install -y pandoc gfortran libblas-dev liblapack-dev libedit-dev llvm-dev libcurl4-openssl-dev ffmpeg
- name: Set up Python
uses: actions/setup-python@v2
Expand Down Expand Up @@ -122,6 +122,7 @@ jobs:
- name: Coveralls
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_SERVICE_NAME: github
run: |
coveralls
Expand Down
9 changes: 5 additions & 4 deletions scprep/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
import scprep.reduce
import scprep.run

import pandas as pd
import pandas as _pd
import packaging.version as _packaging_version

if int(pd.__version__.split(".")[1]) < 26:
if _packaging_version.parse(_pd.__version__) < _packaging_version.parse("2.0"):

def _fill_value(self):
# Used in reindex_indexer
Expand All @@ -26,6 +27,6 @@ def _fill_value(self):
except AttributeError:
return self.values.dtype.na_value

from pandas.core.internals.blocks import ExtensionBlock
from pandas.core.internals.blocks import ExtensionBlock as _ExtensionBlock

setattr(ExtensionBlock, "fill_value", property(_fill_value))
setattr(_ExtensionBlock, "fill_value", property(_fill_value))
12 changes: 11 additions & 1 deletion scprep/plot/histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ def histogram(
title=None,
fontsize=None,
histtype="stepfilled",
label=None,
legend=True,
alpha=None,
filename=None,
dpi=None,
Expand Down Expand Up @@ -114,6 +116,10 @@ def histogram(
each other.
'step' generates a lineplot that is by default unfilled.
'stepfilled' generates a lineplot that is by default filled.
label : str or None, optional (default: None)
String, or sequence of strings to match multiple datasets.
legend : bool, optional (default: True)
Show the legend if ``label`` is given.
alpha : float, optional (default: 1 for a single dataset, 0.5 for multiple)
Histogram transparency
filename : str or None (default: None)
Expand Down Expand Up @@ -152,7 +158,7 @@ def histogram(
if abs_min == 0:
abs_min = 0.1
bins = _symlog_bins(xmin, xmax, abs_min, bins=bins)
ax.hist(data, bins=bins, histtype=histtype, alpha=alpha, **kwargs)
ax.hist(data, bins=bins, histtype=histtype, alpha=alpha, label=label, **kwargs)

if log == "x" or log is True:
ax.set_xscale("symlog", linthresh=abs_min)
Expand All @@ -172,6 +178,10 @@ def histogram(
else:
for c in cutoff:
ax.axvline(c, color="red")

if label is not None and legend:
ax.legend()

# save and show
if show_fig:
show(fig)
Expand Down
26 changes: 22 additions & 4 deletions scprep/run/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,15 @@ def _pysce2rpy(pyobject):


def _is_r_object(obj):
return "rpy2.robjects" in str(type(obj)) or obj is rpy2.rinterface.NULL
return (
"rpy2.robjects" in str(type(obj))
or "rpy2.rinterface" in str(type(obj))
or obj is rpy2.rinterface.NULL
)


def _is_builtin(obj):
return isinstance(obj, (int, str, float))


@utils._with_pkg(pkg="rpy2", min_version="3.0")
Expand Down Expand Up @@ -83,7 +91,12 @@ def rpy2py(robject):
else:
break
if _is_r_object(robject):
warnings.warn("Object not converted: {}".format(robject), RuntimeWarning)
warnings.warn(
"Object not converted: {} (type {})".format(
robject, type(robject).__name__
),
RuntimeWarning,
)
return robject


Expand Down Expand Up @@ -119,6 +132,11 @@ def py2rpy(pyobject):
pass
else:
break
if not _is_r_object(pyobject):
warnings.warn("Object not converted: {}".format(pyobject), RuntimeWarning)
if not _is_r_object(pyobject) and not _is_builtin(pyobject):
warnings.warn(
"Object not converted: {} (type {})".format(
pyobject, type(pyobject).__name__
),
RuntimeWarning,
)
return pyobject
2 changes: 1 addition & 1 deletion scprep/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# author: Scott Gigante <scott.gigante@yale.edu>
# (C) 2018 Krishnaswamy Lab GPLv2

__version__ = "1.0.11"
__version__ = "1.0.12"
4 changes: 2 additions & 2 deletions test/test_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class CustomBlock(ExtensionBlock):

def test_fill_value():
values = pd.Series(np.arange(3), dtype=pd.UInt16Dtype())
custom_block = CustomBlock(values, placement=slice(1, 2))
custom_block = CustomBlock(values, placement=slice(1, 2), ndim=2)
assert pd.isna(custom_block.fill_value)
values = pd.Series(np.arange(3), dtype=pd.SparseDtype(float, 0.0))
custom_block = CustomBlock(values, placement=slice(1, 2))
custom_block = CustomBlock(values, placement=slice(1, 2), ndim=2)
assert not pd.isna(custom_block.fill_value)
1 change: 1 addition & 0 deletions test/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,7 @@ def test_histogram_multiple(self):
scprep.plot.histogram(
[scprep.select.select_rows(self.X, idx=0), [1, 2, 2, 2, 3]],
color=["r", "b"],
label=["one", "two"],
)

def test_histogram_multiple_cutoff(self):
Expand Down

0 comments on commit c0a4845

Please sign in to comment.