You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importmongomockimportnumpyasnpimportpymongo# @mongomock.patch(servers=(("localhost", 27017),))deftest_insert() ->None:
coll=pymongo.MongoClient("mongodb://localhost:27017/my_db").my_db.my_collection# Insert some objectsobjects= [{"a": 1.0}, {"a": float("nan")}]
coll.insert_many(objects)
print(f"Number of documents: {coll.count_documents({})}")
# Filter out objects that are NaNcursor=coll.find({"a": {"$ne": np.nan}})
print("Documents: None of the following should be nan:")
fordocincursor:
print(f' {doc["a"]}')
coll.delete_many({})
test_insert()
Start a mongodb server at mongodb://localhost:27017
Run the code
Result:
❯ python3 mongomock_test.py
Number of documents: 2
Documents: None of the following should be nan:
1.0
Stop the mongodb server
Uncomment line 6 in the python file
Run the code
Result:
❯ python3 mongomock_test.py
Number of documents: 2
Documents: None of the following should be nan:
1.0
nan
Expected result
I expected mongomock to filter out NaNs the way that pymongo does
Activity
Fix NaN handling in operator_eq for MongoDB compatibility
Fix NaN handling in operator_eq to match MongoDB behavior