Browse Source

Allow start==end in stream_insert_context, if no data was provided.

tags/nilmdb-1.6.0^0
Jim Paris 11 years ago
parent
commit
49d04db1d6
4 changed files with 28 additions and 13 deletions
  1. +1
    -1
      nilmdb/client/client.py
  2. +7
    -12
      nilmdb/client/numpyclient.py
  3. +4
    -0
      tests/test_client.py
  4. +16
    -0
      tests/test_numpyclient.py

+ 1
- 1
nilmdb/client/client.py View File

@@ -449,7 +449,7 @@ class StreamInserter(object):
self._interval_start = end_ts

# Double check endpoints
if start_ts is None or end_ts is None:
if (start_ts is None or end_ts is None) or (start_ts == end_ts):
# If the block has no non-comment lines, it's OK
try:
self._get_first_noncomment(block)


+ 7
- 12
nilmdb/client/numpyclient.py View File

@@ -134,16 +134,8 @@ class StreamInserterNumpy(nilmdb.client.client.StreamInserter):
contiguous interval and may be None. 'dtype' is the Numpy
dtype for this stream.
"""
self.last_response = None

super(StreamInserterNumpy, self).__init__(client, path, start, end)
self._dtype = dtype
self._client = client
self._path = path

# Start and end for the overall contiguous interval we're
# filling
self._interval_start = start
self._interval_end = end

# Max rows to send at once
self._max_rows = self._max_data // self._dtype.itemsize
@@ -251,9 +243,12 @@ class StreamInserterNumpy(nilmdb.client.client.StreamInserter):
# Next block continues where this one ended
self._interval_start = end_ts

# If we have no endpoints, it's because we had no data to send.
if start_ts is None or end_ts is None:
return
# If we have no endpoints, or equal endpoints, it's OK as long
# as there's no data to send
if (start_ts is None or end_ts is None) or (start_ts == end_ts):
if len(array) == 0:
return
raise ClientError("have data to send, but invalid start/end times")

# Send it
data = array.tostring()


+ 4
- 0
tests/test_client.py View File

@@ -620,6 +620,10 @@ class TestClient(object):
with client.stream_insert_context("/empty/test", end = 950):
pass

# Equal start and end is OK as long as there's no data
with client.stream_insert_context("/empty/test", start=9, end=9):
pass

# Try various things that might cause problems
with client.stream_insert_context("/empty/test", 1000, 1050) as ctx:
ctx.finalize() # inserts [1000, 1050]


+ 16
- 0
tests/test_numpyclient.py View File

@@ -309,6 +309,22 @@ class TestNumpyClient(object):
with client.stream_insert_numpy_context("/empty/test", end = 950):
pass

# Equal start and end is OK as long as there's no data
with assert_raises(ClientError) as e:
with client.stream_insert_numpy_context("/empty/test",
start=9, end=9) as ctx:
ctx.insert([[9, 9]])
ctx.finalize()
in_("have data to send, but invalid start/end times", str(e.exception))

with client.stream_insert_numpy_context("/empty/test",
start=9, end=9) as ctx:
pass

# reusing a context object is bad
with assert_raises(Exception) as e:
ctx.insert([[9, 9]])

# Try various things that might cause problems
with client.stream_insert_numpy_context("/empty/test",
1000, 1050) as ctx:


Loading…
Cancel
Save