MCPcopy
hub / github.com/hyperopt/hyperopt / insert

Method insert

hyperopt/mongoexp.py:437–451  ·  view source on GitHub ↗

Return a job dictionary by inserting the job dict into the database

(self, job)

Source from the content-addressed store, hash-verified

435 return c if cursor else list(c)
436
437 def insert(self, job):
438 """Return a job dictionary by inserting the job dict into the database"""
439 try:
440 cpy = copy.deepcopy(job)
441 # -- this call adds an _id field to cpy
442 _id = self.jobs.insert(cpy, check_keys=True)
443 # -- so now we return the dict with the _id field
444 assert _id == cpy["_id"]
445 return cpy
446 except pymongo.errors.OperationFailure as e:
447 # -- translate pymongo error class into hyperopt error class
448 # This was meant to make it easier to catch insertion errors
449 # in a generic way even if different databases were used.
450 # ... but there's just MongoDB so far, so kinda goofy.
451 raise OperationFailure(e)
452
453 def delete(self, job):
454 """Delete job[s]"""

Callers 2

_insert_trial_docsMethod · 0.80

Calls 1

OperationFailureClass · 0.85

Tested by 1