Skip to content

Commit fc1c4db

Browse files
authored
Merge pull request #112 from icbi-lab/fix/compatibility
Compatibility fixes
2 parents 90ba34b + 21f9bbe commit fc1c4db

8 files changed

+26
-11
lines changed

docs/tutorials/tutorial_3k_tcr.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -494,5 +494,9 @@ ir.pl.repertoire_overlap(adata, 'sample', dendro_only=True, heatmap_cats=['sourc
494494
```
495495

496496
```python
497-
ir.pl.repertoire_overlap(adata, 'sample', pair_to_plot=('LN2', 'LT2'))
497+
ir.pl.repertoire_overlap(adata, 'sample', pair_to_plot=['LN2', 'LT2'])
498+
```
499+
500+
```python
501+
498502
```

pyproject.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ classifiers = [
1919
requires-python = '>= 3.6'
2020
requires = [
2121
'get_version',
22-
'scanpy',
23-
# pandas <1 until scanpy is fully compatible...
24-
'pandas<1',
22+
'anndata>=0.7.1',
23+
'scanpy>=1.4.5.post3',
24+
'pandas>=0.21',
2525
'numpy',
2626
'scipy',
2727
'parasail',

scirpy/_plotting/_repertoire_overlap.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,11 @@ def repertoire_overlap(
8181
if heatmap_cats is not None:
8282
clust_colors, leg_colors = [], []
8383
for lbl in heatmap_cats:
84-
labels = adata.obs.groupby([groupby, lbl]).agg("size").reset_index()
84+
labels = (
85+
adata.obs.groupby([groupby, lbl], observed=True)
86+
.agg("size")
87+
.reset_index()
88+
)
8589
label_levels = labels[lbl].unique()
8690
label_pal = sns.cubehelix_palette(
8791
label_levels.size,
@@ -153,7 +157,7 @@ def repertoire_overlap(
153157
if valid_pairs:
154158
if o_df.shape[1] == 2:
155159
o_df = o_df.loc[(o_df.sum(axis=1) != 0), :]
156-
o_df = o_df.groupby(pair_to_plot).agg("size")
160+
o_df = o_df.groupby(pair_to_plot, observed=True).agg("size")
157161
o_df = o_df.reset_index()
158162
o_df.columns = ("x", "y", "z")
159163
o_df["z"] -= o_df["z"].min()

scirpy/_tools/_clonal_expansion.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def _clip_and_count(
2626
groupby = [groupby] if isinstance(groupby, str) else groupby
2727
groupby_cols = [target_col] if groupby is None else groupby + [target_col]
2828
clonotype_counts = (
29-
adata.obs.groupby(groupby_cols)
29+
adata.obs.groupby(groupby_cols, observed=True)
3030
.size()
3131
.reset_index(name="tmp_count")
3232
.assign(

scirpy/_tools/_clonotypes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def _define_clonotypes_no_graph(
4949
clonotype_col = np.array(
5050
[
5151
"clonotype_{}".format(x)
52-
for x in adata.obs.groupby(groupby_cols[flavor]).ngroup()
52+
for x in adata.obs.groupby(groupby_cols[flavor], observed=True).ngroup()
5353
]
5454
)
5555
clonotype_col[

scirpy/_tools/_diversity.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ def _shannon_entropy(freq):
5252

5353
tcr_obs = adata.obs.loc[~_is_na(adata.obs[target_col]), :]
5454
clono_counts = (
55-
tcr_obs.groupby([groupby, target_col]).size().reset_index(name="count")
55+
tcr_obs.groupby([groupby, target_col], observed=True)
56+
.size()
57+
.reset_index(name="count")
5658
)
5759

5860
diversity = dict()

scirpy/_tools/_group_abundance.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ def _group_abundance(
2626
# Calculate distribution of lengths in each group. Use sum instead of count
2727
# to reflect weights
2828
group_counts = (
29-
tcr_obs.groupby([groupby, target_col])["count", "weight"]
29+
tcr_obs.loc[:, [groupby, target_col, "count", "weight"]]
30+
.groupby([groupby, target_col], observed=True)
3031
.sum()
3132
.reset_index()
3233
.rename(columns={"weight": "weighted_count"})

scirpy/_tools/_repertoire_overlap.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ def repertoire_overlap(
6363
)
6464

6565
# Create a weighted matrix of clonotypes
66-
df = df.groupby([target_col, groupby]).agg({"cell_weights": "sum"}).reset_index()
66+
df = (
67+
df.groupby([target_col, groupby], observed=True)
68+
.agg({"cell_weights": "sum"})
69+
.reset_index()
70+
)
6771
df = df.pivot(index=groupby, columns=target_col, values="cell_weights")
6872
df = df.fillna(0)
6973

0 commit comments

Comments
 (0)