Skip to content

MongoStore.update: add numpy 2.0 types to test (Issue #1006) #1007

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ dependencies = [
"ruamel.yaml>=0.17",
"pydantic>=2.0",
"pydantic-settings>=2.0.3",
"pymongo>=4.2.0",
"pymongo>=4.2.0,<4.11",
"monty>=2024.5.24",
"mongomock>=3.10.0",
"pydash>=4.1.0",
Expand Down
12 changes: 8 additions & 4 deletions tests/stores/test_mongolike.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from unittest import mock

import mongomock.collection
import numpy as np
import orjson
import pymongo.collection
import pytest
Expand Down Expand Up @@ -117,13 +118,16 @@ def test_mongostore_distinct(mongostore):


def test_mongostore_update(mongostore):
mongostore.update({"e": 6, "d": 4}, key="e")
# See https://github.com/materialsproject/maggma/issues/1006
# bson does not natively encode numpy types, so we need to convert them to
# native types. See https://pymongo.readthedocs.io/en/stable/api/bson/
mongostore.update({"e": 6, "d": 4, "bool": np.bool_(5)}, key="e")
assert mongostore.query_one(criteria={"d": {"$exists": 1}}, properties=["d"])["d"] == 4

mongostore.update([{"e": 7, "d": 8, "f": 9}], key=["d", "f"])
assert mongostore.query_one(criteria={"d": 8, "f": 9}, properties=["e"])["e"] == 7
mongostore.update([{"e": 7, "d": np.int64(8), "f": 9}], key=["d", "f"])
assert mongostore.query_one(criteria={"d": 8, "f": np.float64(9)}, properties=["e"])["e"] == 7

mongostore.update([{"e": 11, "d": 8, "f": 9}], key=["d", "f"])
mongostore.update([{"e": 11, "d": np.int32(8), "f": np.float32(9)}], key=["d", "f"])
assert mongostore.query_one(criteria={"d": 8, "f": 9}, properties=["e"])["e"] == 11

test_schema = {
Expand Down
Loading