Skip to content

Commit

Permalink
Merge pull request #51 from KrishnaswamyLab/dev
Browse files Browse the repository at this point in the history
scprep 0.12.2
  • Loading branch information
scottgigante authored Jul 1, 2019
2 parents 5eff89e + 2aee20f commit f64a098
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 27 deletions.
15 changes: 10 additions & 5 deletions scprep/plot/scatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,11 @@ def discrete(self):
return True
else:
# guess based on number of unique elements
return self.n_c_unique <= 20
if self.n_c_unique > 20:
return False
else:
# are the unique elements integer-like?
return np.allclose(self.c_unique % 1, 0, atol=1e-4)

@property
def c_discrete(self):
Expand All @@ -173,12 +177,13 @@ def c_discrete(self):

@property
def c(self):
if self.constant_c() or self.array_c():
if self.constant_c():
return self._c
elif self.discrete:
return self.c_discrete[self.plot_idx]
else:
elif self.array_c() or not self.discrete:
return self._c[self.plot_idx]
else:
# discrete c
return self.c_discrete[self.plot_idx]

@property
def labels(self):
Expand Down
16 changes: 8 additions & 8 deletions scprep/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,32 +48,32 @@ def _check_columns_compatible(*data):
for d in data:
if not _get_column_length(d) == _get_column_length(data[0]):
raise ValueError(
"Expected all data to have the same number of "
"Expected `data` and `extra_data` to have the same number of "
"columns. Got {}".format(
[_get_column_length(d) for d in data]))
if isinstance(d, (pd.DataFrame, pd.Series)) and \
isinstance(data[0], (pd.DataFrame, pd.Series)):
if not np.all(_get_columns(data[0]) == _get_columns(d)):
raise ValueError(
"Expected all pandas inputs to have the same columns. "
"Fix with "
"`scprep.select.select_cols(extra_data, data.columns)`")
"Expected `data` and `extra_data` pandas inputs to have "
"the same column names. Fix with "
"`scprep.select.select_cols(*extra_data, data.columns)`")


def _check_rows_compatible(*data):
for d in data:
if not _get_row_length(d) == _get_row_length(data[0]):
raise ValueError(
"Expected all data to have the same number of "
"Expected `data` and `extra_data` to have the same number of "
"rows. Got {}".format(
[d.shape[0] for d in data]))
if isinstance(d, (pd.DataFrame, pd.Series)) and \
isinstance(data[0], (pd.DataFrame, pd.Series)):
if not np.all(data[0].index == d.index):
raise ValueError(
"Expected all pandas inputs to have the same index. "
"Fix with "
"`scprep.select.select_rows(extra_data, data.index)`")
"Expected `data` and `extra_data` pandas inputs to have "
"the same index. Fix with "
"`scprep.select.select_rows(*extra_data, data.index)`")


def _convert_dataframe_1d(idx):
Expand Down
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 <[email protected]>
# (C) 2018 Krishnaswamy Lab GPLv2

__version__ = "0.12.1"
__version__ = "0.12.2"
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
'tables',
'h5py',
'rpy2>=3.0',
'matplotlib>=3.0.0',
'coverage',
'coveralls'
]
Expand All @@ -32,6 +31,10 @@

if sys.version_info[:2] < (3, 5):
raise RuntimeError("Python version >=3.5 required.")
elif sys.version_info[:2] < (3, 6):
test_requires += ['matplotlib>=3.0,<3.1']
else:
test_requires += ['matplotlib>=3.0']

version_py = os.path.join(os.path.dirname(
__file__), 'scprep', 'version.py')
Expand Down
30 changes: 28 additions & 2 deletions test/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ def test_array_c(self):
c=self.array_c)
assert params.array_c()
assert not params.constant_c()
np.testing.assert_array_equal(params.x, params._x[params.plot_idx])
np.testing.assert_array_equal(params.y, params._y[params.plot_idx])
np.testing.assert_array_equal(params.c, params._c[params.plot_idx])
assert params.discrete is None
assert params.legend is False
assert params.vmin is None
Expand All @@ -249,6 +252,9 @@ def test_continuous(self):
params = _ScatterParams(x=self.x, y=self.y, c=self.c)
assert not params.array_c()
assert not params.constant_c()
np.testing.assert_array_equal(params.x, params._x[params.plot_idx])
np.testing.assert_array_equal(params.y, params._y[params.plot_idx])
np.testing.assert_array_equal(params.c, params._c[params.plot_idx])
assert params.discrete is False
assert params.legend is True
assert params.cmap_scale == 'linear'
Expand All @@ -257,6 +263,9 @@ def test_continuous(self):
c=np.round(self.c % 1, 1))
assert not params.array_c()
assert not params.constant_c()
np.testing.assert_array_equal(params.x, params._x[params.plot_idx])
np.testing.assert_array_equal(params.y, params._y[params.plot_idx])
np.testing.assert_array_equal(params.c, params._c[params.plot_idx])
assert params.discrete is False
assert params.legend is True
assert params.labels is None
Expand All @@ -268,6 +277,10 @@ def test_discrete_tab10(self):
c=np.where(self.c > 0, '+', '-'))
assert not params.array_c()
assert not params.constant_c()
np.testing.assert_array_equal(params.x, params._x[params.plot_idx])
np.testing.assert_array_equal(params.y, params._y[params.plot_idx])
np.testing.assert_array_equal(
params.c, params.c_discrete[params.plot_idx])
assert params.discrete is True
assert params.legend is True
assert params.vmin is None
Expand All @@ -276,8 +289,8 @@ def test_discrete_tab10(self):
np.testing.assert_equal(params.cmap.colors, plt.cm.tab10.colors[:2])

def test_discrete_tab20(self):
params = _ScatterParams(x=self.x, y=self.y, discrete=True,
c=np.round(self.c % 1, 1))
params = _ScatterParams(x=self.x, y=self.y,
c=10 * np.round(self.c % 1, 1))
assert not params.array_c()
assert not params.constant_c()
assert params.discrete is True
Expand All @@ -291,6 +304,19 @@ def test_discrete_tab20(self):
params.cmap.colors,
plt.cm.tab20.colors[:len(np.unique(np.round(self.c % 1, 1)))])

def test_continuous_less_than_20(self):
params = _ScatterParams(x=self.x, y=self.y,
c=np.round(self.c % 1, 1))
assert not params.array_c()
assert not params.constant_c()
assert params.discrete is False
assert params.legend is True
assert params.vmin == 0
assert params.vmax == 1
assert params.cmap_scale == 'linear'
assert params.extend == 'neither'
assert params.cmap is matplotlib.cm.inferno

def test_continuous_tab20_str(self):
params = _ScatterParams(x=self.x, y=self.y, discrete=False,
cmap='tab20', c=np.round(self.c % 1, 1))
Expand Down
20 changes: 10 additions & 10 deletions test/test_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def test_select_cols_2d_list_index(self):
def test_select_cols_unequal_columns(self):
assert_raise_message(
ValueError,
"Expected all data to have the same number of "
"Expected `data` and `extra_data` to have the same number of "
"columns. Got [100, 50]",
scprep.select.select_cols,
self.X,
Expand All @@ -323,7 +323,7 @@ def test_select_cols_unequal_columns(self):
def test_select_rows_unequal_rows(self):
assert_raise_message(
ValueError,
"Expected all data to have the same number of "
"Expected `data` and `extra_data` to have the same number of "
"rows. Got [100, 50]",
scprep.select.select_rows,
self.X,
Expand All @@ -332,19 +332,19 @@ def test_select_rows_unequal_rows(self):
def test_select_cols_conflicting_data(self):
assert_raise_message(
ValueError,
"Expected all pandas inputs to have the same columns. "
"Fix with "
"`scprep.select.select_cols(extra_data, data.columns)`",
"Expected `data` and `extra_data` pandas inputs to have the same "
"column names. Fix with "
"`scprep.select.select_cols(*extra_data, data.columns)`",
scprep.select.select_cols,
self.X,
scprep.select.subsample(self.X.T, n=self.X.shape[0]).T)

def test_select_rows_conflicting_data(self):
assert_raise_message(
ValueError,
"Expected all pandas inputs to have the same index. "
"Fix with "
"`scprep.select.select_rows(extra_data, data.index)`",
"Expected `data` and `extra_data` pandas inputs to have the same "
"index. Fix with "
"`scprep.select.select_rows(*extra_data, data.index)`",
scprep.select.select_rows,
self.X,
scprep.select.subsample(self.X, n=self.X.shape[0]))
Expand Down Expand Up @@ -397,8 +397,8 @@ def test_subsample_mismatch_size(self):
libsize = self.libsize[:25]
assert_raise_message(
ValueError,
"Expected all data to have the same number of rows. "
"Got [100, 25]",
"Expected `data` and `extra_data` to have the same number of "
"rows. Got [100, 25]",
scprep.select.subsample, self.X, libsize, n=20)

def test_subsample_n_too_large(self):
Expand Down

0 comments on commit f64a098

Please sign in to comment.