Skip to content

Commit

Permalink
test_handler_options updates
Browse files Browse the repository at this point in the history
  • Loading branch information
gwbischof committed Aug 28, 2019
1 parent d63a8f5 commit 2d56092
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 23 deletions.
33 changes: 14 additions & 19 deletions databroker/tests/test_broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,11 +617,9 @@ def __call__(*args, **kwrags):

# Use a one-off handler registry.

db._catalog.filler.handler_registry = {'foo': ImageHandler}
ev, ev2 = db.get_events(h, stream_name='injected', fields=['image'],
fill=True)
assert ev['data']['image'].shape == ImageHandler.RESULT.shape
assert ev['filled']['image']
with pytest.raises(NotImplementedError):
ev, ev2 = db.get_events(h, stream_name='injected', fields=['image'],
fill=True, handler_registry= {'foo': ImageHandler})

# Statefully register the handler.
db.reg.register_handler('foo', ImageHandler)
Expand All @@ -639,24 +637,21 @@ def __call__(*args, **kwrags):
assert ev['filled'] is not ev2['filled']
assert not ev['filled']['image']
datum = ev['data']['image']
ev_ret, = db.fill_events([ev], h.descriptors, inplace=True)
assert ev['filled']['image'] == datum
assert not ev2['filled']['image']
ev2_filled = db.fill_event(ev2, inplace=False)
assert ev2_filled['filled']['image'] == ev2['data']['image']
ev_ret2 = db.fill_events([ev], h.descriptors, inplace=True)
ev_ret3 = db.fill_events(ev_ret2, h.descriptors, inplace=True)
ev = next(ev_ret3)
assert ev['filled']['image'] == datum

with pytest.raises(NotImplementedError):
ev_ret, = db.fill_events([ev], h.descriptors, inplace=True)

with pytest.raises(NotImplementedError):
ev2_filled = db.fill_event(ev2, inplace=False)

# table with fill=False (default)
table = db.get_table(h, stream_name='injected', fields=['image'])
datum_id = table['image'].iloc[0]
assert isinstance(datum_id, str)
with pytest.raises(NotImplementedError):
table = db.get_table(h, stream_name='injected',
fields=['image'], fill=False)

# table with fill=True
table = db.get_table(h, stream_name='injected', fields=['image'],
fill=True)
table = db.get_table(h, stream_name='injected',
fields=['image'], fill=True)
img = table['image'].iloc[0]
assert not isinstance(img, str)
assert img.shape == ImageHandler.RESULT.shape
Expand Down
22 changes: 18 additions & 4 deletions databroker/v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ def get_events(self,
yield doc

def get_table(self,
headers, stream_name='primary', fields=None, fill=False,
headers, stream_name='primary', fields=None, fill=None,
handler_registry=None,
convert_times=True, timezone=None, localize_times=True):
"""
Expand Down Expand Up @@ -596,6 +596,11 @@ def get_table(self,
"the Broker is initialized, usually specified "
"in a configuration file.")

if not fill:
raise NotImplementedError("The fill argument is no longer "
"implemented. Use get_documents if you "
"need external references.")

headers = _ensure_list(headers)
dfs = []
for header in headers:
Expand Down Expand Up @@ -638,7 +643,7 @@ def get_images(self, headers, name,
raise NotImplementError(
"The handler_registry parameter is no longer supported "
"and must be None.")
dataset = xarray.concat(datasets)
dataset = xarray.merge(datasets)
data_array = dataset[name]
return Images(data_array=data_array)

Expand Down Expand Up @@ -933,8 +938,17 @@ def insert(self, name, doc):
if name == 'stop':
self._catalog.force_reload()



def fill_event(*args, **kwargs):
raise NotImplementedError("This method is no longer supported. If you "
"need this please contact the developers by "
"opening an issue here: "
"https://github.com/bluesky/databroker/issues/new ")

def fill_events(*args, **kwargs):
raise NotImplementedError("This method is no longer supported. If you "
"need this please contact the developers by "
"opening an issue here: "
"https://github.com/bluesky/databroker/issues/new ")
class Header:
"""
This supports the original Header API but implemented on intake's Entry.
Expand Down

0 comments on commit 2d56092

Please sign in to comment.