Skip to content

Commit

Permalink
Merge branch 'main' into filestore
Browse files Browse the repository at this point in the history
  • Loading branch information
rkingsbury committed Apr 11, 2022
2 parents 2c815a5 + 7575356 commit 2f3b891
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/maggma/stores/mongolike.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,9 +638,15 @@ def groupby(
generator returning tuples of (key, list of elemnts)
"""
keys = keys if isinstance(keys, list) else [keys]

if properties is None:
properties = []
if isinstance(properties, dict):
properties = list(properties.keys())

data = [
doc
for doc in self.query(properties=keys, criteria=criteria)
for doc in self.query(properties=keys + properties, criteria=criteria)
if all(has(doc, k) for k in keys)
]

Expand Down
7 changes: 5 additions & 2 deletions tests/stores/test_mongolike.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,12 @@ def test_groupby(memorystore):
],
key="f",
)
data = list(memorystore.groupby("d"))
data = list(memorystore.groupby("d", properties={"e": 1, "f": 1}))
assert len(data) == 2
grouped_by_9 = [g[1] for g in data if g[0]["d"] == 9][0]
assert len(grouped_by_9) == 3
assert all([d.get("f", False) for d in grouped_by_9])
assert all([d.get("e", False) for d in grouped_by_9])
grouped_by_10 = [g[1] for g in data if g[0]["d"] == 10][0]
assert len(grouped_by_10) == 1

Expand All @@ -289,8 +291,9 @@ def test_groupby(memorystore):
],
key="f",
)
data = list(memorystore.groupby("e.d"))
data = list(memorystore.groupby("e.d", properties=["f"]))
assert len(data) == 2
assert data[0][1][0].get("f", False)


# Monty store tests
Expand Down

0 comments on commit 2f3b891

Please sign in to comment.