Skip to content

Commit

Permalink
hotfix pymongo collection issue
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasprobst committed Dec 14, 2024
1 parent d028a1f commit 660310b
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 58 deletions.
98 changes: 49 additions & 49 deletions docs/userguide/database/mongoDB.ipynb

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions h5rdmtoolbox/database/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

import h5py
import numpy as np
import pymongo
from pymongo.collection import Collection
from pymongo.errors import InvalidDocument

from .interface import ExtHDF5DBInterface
from .. import protected_attributes
Expand Down Expand Up @@ -182,7 +183,7 @@ def _generate_dataset_document(

def _insert_dataset(
dataset: h5py.Dataset,
collection: pymongo.collection.Collection,
collection: Collection,
axis=None,
update: bool = True,
ignore_attrs: List[str] = None,
Expand Down Expand Up @@ -213,7 +214,7 @@ def _insert_dataset(

def _insert_group(
group: h5py.Group,
collection: pymongo.collection.Collection,
collection: Collection,
recursive: bool = False,
update: bool = True,
include_dataset: bool = True,
Expand All @@ -236,8 +237,8 @@ def _insert_group(
tree["filename"] = filename
try:
collection.insert_one(make_dict_mongo_compatible(tree))
except pymongo.errors.InvalidDocument as e:
raise pymongo.errors.InvalidDocument(
except InvalidDocument as e:
raise InvalidDocument(
f'Could not insert dict: \n{make_dict_mongo_compatible(tree)}\nOriginal error: {e}') from e
return collection

Expand Down Expand Up @@ -308,7 +309,7 @@ class MongoDB(ExtHDF5DBInterface):
(see module `lazy`).
"""

def __init__(self, collection: pymongo.collection.Collection):
def __init__(self, collection: Collection):
self.collection = collection

def insert_dataset(self, dataset: h5py.Dataset, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ python-forge==18.6.0
requests>=2.32.3
rdflib>=7.0.0
# database:
pymongo>=4.2.0,<4.9.0
pymongo>=4.2.0,<=4.10.1
# csv
pandas>=1.4.3
# snt
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ install_requires =

[options.extras_require]
database=
pymongo>=4.2.0,<4.9.0
pymongo>=4.2.0,<=4.10.1
layout_validation=
tabulate>=0.8.10,<=0.9.0
csv =
Expand Down
3 changes: 2 additions & 1 deletion tests/database/test_mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import mongomock
import numpy as np
import pymongo
from pymongo.errors import ServerSelectionTimeoutError
from skimage.feature import graycomatrix, graycoprops
from sklearn.datasets import load_digits # ! pip install scikit-learn

Expand All @@ -25,7 +26,7 @@
def get_client():
print('Using real mongoDB server over mongomock')
return pymongo.MongoClient()
except pymongo.errors.ServerSelectionTimeoutError as err:
except ServerSelectionTimeoutError as err:

def get_client():
print('Using mongomock')
Expand Down

0 comments on commit 660310b

Please sign in to comment.