Skip to content

Commit

Permalink
deprecate pd.SparseDataFrame, closes #190
Browse files Browse the repository at this point in the history
  • Loading branch information
scottgigante committed Oct 30, 2020
1 parent 88eec77 commit 09e888c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
10 changes: 6 additions & 4 deletions python/magic/magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,7 @@ def knn_max(self, value):

@property
def diff_op(self):
"""The diffusion operator calculated from the data
"""
"""The diffusion operator calculated from the data"""
if self.graph is not None:
return self.graph.diff_op
else:
Expand Down Expand Up @@ -501,7 +500,7 @@ def fit(self, X, graph=None):
def _parse_genes(self, X, genes):
if (
genes is None
and isinstance(X, (pd.SparseDataFrame, sparse.spmatrix))
and (sparse.issparse(X) or scprep.utils.is_sparse_dataframe(X))
and np.prod(X.shape) > 5000 * 20000
):
warnings.warn(
Expand Down Expand Up @@ -867,7 +866,10 @@ def _impute(
ax.plot(x, error_vec)
if t_opt is not None:
ax.plot(
t_opt, error_vec[t_opt - 1], "ro", markersize=10,
t_opt,
error_vec[t_opt - 1],
"ro",
markersize=10,
)
ax.plot(x, np.full(len(error_vec), threshold), "k--")
ax.set_xlabel("t")
Expand Down
5 changes: 1 addition & 4 deletions python/magic/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,7 @@ def animate_magic(
show = False

data_magic = scprep.select.select_cols(data, idx=genes)
if isinstance(data_magic, pd.SparseDataFrame):
data_magic = data_magic.to_dense()
elif sparse.issparse(data_magic):
data_magic = data_magic.toarray()
data_magic = scprep.utils.toarray(data_magic)
c = data_magic[gene_color] if gene_color is not None else None
sc = ax.scatter(data_magic[gene_x], data_magic[gene_y], c=c, cmap=cmap)
ax.set_title("t = 0")
Expand Down
4 changes: 2 additions & 2 deletions python/magic/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,11 @@ def matrix_is_equivalent(X, Y):

def convert_to_same_format(data, target_data, columns=None, prevent_sparse=False):
# create new data object
if isinstance(target_data, pd.SparseDataFrame):
if scprep.utils.is_sparse_dataframe(target_data):
if prevent_sparse:
data = pd.DataFrame(data)
else:
data = pd.SparseDataFrame(data)
data = scprep.utils.SparseDataFrame(data)
pandas = True
elif isinstance(target_data, pd.DataFrame):
data = pd.DataFrame(data)
Expand Down
2 changes: 1 addition & 1 deletion python/magic/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.0.4a0"
__version__ = "2.0.4"

0 comments on commit 09e888c

Please sign in to comment.