Skip to content

Commit

Permalink
Loading $uuid as UUID representation
Browse files Browse the repository at this point in the history
BSON binary subtype 3 is a legacy  UUID format. By default, JSON is deserialized as subtype 4. With this fix, it will deserialize $uuid as binary subtype 3

Fix for - e-mission/e-mission-docs#856 (comment)
  • Loading branch information
swastis10 committed Mar 8, 2023
1 parent 5375321 commit 6ac02a2
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion emission/tests/modellingTests/TestRunGreedyIncrementalModel.py
Expand Up @@ -6,6 +6,10 @@
import time
import pandas as pd
import bson.json_util as bju
import bson
from bson.json_util import loads
from itertools import chain
from bson.binary import Binary, UuidRepresentation

import emission.analysis.modelling.trip_model.model_storage as eamums
import emission.analysis.modelling.trip_model.model_type as eamumt
Expand All @@ -31,7 +35,13 @@ def setUp(self):

# emission/tests/data/real_examples/shankari_2016-06-20.expected_confirmed_trips
self.user_id = uuid.UUID('aa9fdec9-2944-446c-8ee2-50d79b3044d3')
# self.user_id = Binary.from_uuid(uuid.UUID('aa9fdec9-2944-446c-8ee2-50d79b3044d3'), UuidRepresentation.PYTHON_LEGACY)
print("USER IDDDDD", self.user_id)
self.ts = esta.TimeSeries.get_time_series(self.user_id)
print("TSSSS", self.ts.find_entries([esdatq.CONFIRMED_TRIP_KEY]))
# for ent in self.ts.find_entries([esdatq.CONFIRMED_TRIP_KEY]):
# res = list(chain(self.ts.find_entries([esdatq.CONFIRMED_TRIP_KEY])))
# print("RES", res)
self.new_trips_per_invocation = 3
self.model_type = eamumt.ModelType.GREEDY_SIMILARITY_BINNING
self.model_storage = eamums.ModelStorage.DOCUMENT_DATABASE
Expand All @@ -50,7 +60,7 @@ def setUp(self):
# load in trips from a test file source
input_file = 'emission/tests/data/real_examples/shankari_2016-06-20.expected_confirmed_trips'
with open(input_file, 'r') as f:
trips_json = json.loads(f.read(), object_hook=bju.object_hook)
trips_json = bju.loads(f.read(), json_options = bju.LEGACY_JSON_OPTIONS.with_options(strict_uuid= False, uuid_representation= UuidRepresentation.PYTHON_LEGACY))
trips = [ecwe.Entry(r) for r in trips_json]
logging.debug(f'loaded {len(trips)} trips from {input_file}')
self.ts.bulk_insert(trips)
Expand Down

1 comment on commit 6ac02a2

@shankari
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@swastis10 Does this fix the test? Would be good to indicate that in the commit message.
Also, if this is the case, then why doesn't this affect all the other file reads (e.g. in emission/tests/analysisTests/intakeTests/TestPipelineRealData.py).

Please sign in to comment.