diff --git a/scprep/plot/scatter.py b/scprep/plot/scatter.py index 5bd3423d..6821c049 100644 --- a/scprep/plot/scatter.py +++ b/scprep/plot/scatter.py @@ -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): @@ -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): diff --git a/scprep/select.py b/scprep/select.py index cb00ed06..6d055be5 100644 --- a/scprep/select.py +++ b/scprep/select.py @@ -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): diff --git a/scprep/version.py b/scprep/version.py index 0f8fe375..54306210 100644 --- a/scprep/version.py +++ b/scprep/version.py @@ -1,4 +1,4 @@ # author: Scott Gigante # (C) 2018 Krishnaswamy Lab GPLv2 -__version__ = "0.12.1" +__version__ = "0.12.2" diff --git a/setup.py b/setup.py index c4b0971a..3871b98b 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,6 @@ 'tables', 'h5py', 'rpy2>=3.0', - 'matplotlib>=3.0.0', 'coverage', 'coveralls' ] @@ -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') diff --git a/test/test_plot.py b/test/test_plot.py index 12a9b793..4b3c34be 100644 --- a/test/test_plot.py +++ b/test/test_plot.py @@ -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 @@ -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' @@ -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 @@ -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 @@ -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 @@ -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)) diff --git a/test/test_select.py b/test/test_select.py index 0ed3e096..e05738e3 100644 --- a/test/test_select.py +++ b/test/test_select.py @@ -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, @@ -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, @@ -332,9 +332,9 @@ 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) @@ -342,9 +342,9 @@ def test_select_cols_conflicting_data(self): 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])) @@ -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):