Skip to content
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

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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