Skip to content

Commit 50e7d9f

Browse files
committed
fix MolGrid.get_selection
1 parent 66f4757 commit 50e7d9f

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [0.2.4] - 2022/05/??
8+
### Fixed
9+
- Calling `MolGrid.get_selection()` when 2 grids with different names are present should
10+
now display the selection of the grid itself, and not the selection corresponding to
11+
indices of the grid that was last interacted with.
12+
713
## [0.2.3] - 2022/05/10
814
### Fixed
915
- Doing a substructure search on molecules with explicit hydrogens should now highlight

mols2grid/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.2.3"
1+
__version__ = "0.2.4"

mols2grid/molgrid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ def get_selection(self):
627627
-------
628628
pandas.DataFrame
629629
"""
630-
sel = list(register.get_selection().keys())
630+
sel = list(register.get_selection(self._grid_id).keys())
631631
return (self.dataframe.loc[self.dataframe["mols2grid-id"].isin(sel)]
632632
.drop(columns=self._extra_columns))
633633

tests/test_molgrid.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,13 @@ def test_mol_to_img_png():
215215
assert img.startswith('<img src="data:image/png;base64')
216216

217217
def test_get_selection(df):
218-
grid = MolGrid(df, mol_col="mol")
218+
grid = MolGrid(df, mol_col="mol", name="grid")
219+
other = MolGrid(df, mol_col="mol", name="other")
220+
register._update_current_grid("grid")
219221
register._set_selection(0, "")
220-
new = grid.get_selection()
221-
assert_equal(new.values,
222-
df.iloc[0:1].values)
222+
assert grid.get_selection().equals(df.head(1))
223+
assert other.get_selection().equals(df.head(0)) # empty dataframe
224+
register._clear()
223225

224226
def test_save(grid_otf):
225227
with NamedTemporaryFile("w", suffix=".html") as f:

0 commit comments

Comments
 (0)