@@ -210,7 +210,7 @@ def count(
210
210
pointwidth = min (
211
211
pointwidth ,
212
212
pw .from_nanoseconds (to_nanoseconds (end ) - to_nanoseconds (start )) - 1 ,
213
- )
213
+ )
214
214
points = self .aligned_windows (start , end , pointwidth , version )
215
215
return sum ([point .count for point , _ in points ])
216
216
@@ -583,7 +583,7 @@ def insert(self, data, merge="never"):
583
583
version = 0
584
584
i = 0
585
585
while i < len (data ):
586
- thisBatch = data [i : i + INSERT_BATCH_SIZE ]
586
+ thisBatch = data [i : i + INSERT_BATCH_SIZE ]
587
587
version = self ._btrdb .ep .insert (self ._uuid , thisBatch , merge )
588
588
i += INSERT_BATCH_SIZE
589
589
return version
@@ -1435,20 +1435,22 @@ def __repr__(self):
1435
1435
## StreamSet Classes
1436
1436
##########################################################################
1437
1437
1438
+
1438
1439
@delayed
1439
1440
def get_metadata (stream ):
1440
- columns = [' collection' , ' tags' , ' annotations' , ' stream' , ' uuid' ]
1441
+ columns = [" collection" , " tags" , " annotations" , " stream" , " uuid" ]
1441
1442
stream .refresh_metadata ()
1442
- metadata = {c : (getattr (stream , f"_{ c } " ) if c != 'stream' else stream )
1443
- for c in columns }
1443
+ metadata = {
1444
+ c : (getattr (stream , f"_{ c } " ) if c != "stream" else stream ) for c in columns
1445
+ }
1444
1446
return metadata
1445
1447
1448
+
1446
1449
class StreamSetBase (Sequence ):
1447
1450
"""
1448
1451
A lighweight wrapper around a list of stream objects
1449
1452
"""
1450
1453
1451
-
1452
1454
def __init__ (self , streams ):
1453
1455
self ._streams = streams
1454
1456
if len (self ._streams ) < 1 :
@@ -1467,11 +1469,11 @@ def __init__(self, streams):
1467
1469
self .depth = 0
1468
1470
1469
1471
# create a DataFrame to store the metadata for filtering
1470
- _columns = ['collection' , 'tags' , 'annotations' , 'stream' , 'uuid' ]
1471
1472
_metadata = compute ([get_metadata (s ) for s in self ._streams ])[0 ]
1472
1473
_metadata = pd .DataFrame (_metadata )
1473
- self ._metadata = (_metadata .join (pd .json_normalize (_metadata ['tags' ]))
1474
- .drop (columns = ['tags' , 'annotations' ]))
1474
+ self ._metadata = _metadata .join (pd .json_normalize (_metadata ["tags" ])).drop (
1475
+ columns = ["tags" , "annotations" ]
1476
+ )
1475
1477
1476
1478
@property
1477
1479
def allow_window (self ):
@@ -1735,55 +1737,67 @@ def filter(
1735
1737
# filter by collection
1736
1738
if collection is not None :
1737
1739
if isinstance (collection , RE_PATTERN ):
1738
- tf = (tf & obj ._metadata .collection .str .contains (collection .pattern , case = False , regex = True ))
1740
+ tf = tf & obj ._metadata .collection .str .contains (
1741
+ collection .pattern , case = False , regex = True
1742
+ )
1739
1743
elif isinstance (collection , str ):
1740
- tf = (tf & obj ._metadata .collection .str .contains (collection , case = False , regex = False ))
1744
+ tf = tf & obj ._metadata .collection .str .contains (
1745
+ collection , case = False , regex = False
1746
+ )
1741
1747
else :
1742
1748
raise BTRDBTypeError ("collection must be string or compiled regex" )
1743
1749
1744
1750
# filter by name
1745
1751
if name is not None :
1746
1752
if isinstance (name , RE_PATTERN ):
1747
- tf = (tf & obj ._metadata .name .str .contains (name .pattern , case = False , regex = True ))
1753
+ tf = tf & obj ._metadata .name .str .contains (
1754
+ name .pattern , case = False , regex = True
1755
+ )
1748
1756
elif isinstance (name , str ):
1749
- tf = ( tf & obj ._metadata .name .str .contains (name , case = False , regex = False ) )
1757
+ tf = tf & obj ._metadata .name .str .contains (name , case = False , regex = False )
1750
1758
else :
1751
1759
raise BTRDBTypeError ("name must be string or compiled regex" )
1752
1760
1753
1761
# filter by unit
1754
1762
if unit is not None :
1755
1763
if isinstance (unit , RE_PATTERN ):
1756
- tf = (tf & obj ._metadata .unit .str .contains (unit , case = False , regex = True ))
1764
+ tf = tf & obj ._metadata .unit .str .contains (
1765
+ unit .pattern , case = False , regex = True
1766
+ )
1757
1767
elif isinstance (unit , str ):
1758
- tf = ( tf & obj ._metadata .name .str .contains (unit , case = False , regex = False ) )
1768
+ tf = tf & obj ._metadata .name .str .contains (unit , case = False , regex = False )
1759
1769
else :
1760
1770
raise BTRDBTypeError ("unit must be string or compiled regex" )
1761
1771
1762
1772
# filter by tags
1763
1773
if tags :
1764
- tf = (tf & obj ._metadata .loc [:, obj ._metadata .columns .isin (tags .keys ())]
1765
- .apply (lambda x : x .str .contains (tags [x .name ], case = False , regex = False ))
1766
- .all (axis = 1 ))
1774
+ tf = tf & obj ._metadata .loc [
1775
+ :, obj ._metadata .columns .isin (tags .keys ())
1776
+ ].apply (
1777
+ lambda x : x .str .contains (tags [x .name ], case = False , regex = False )
1778
+ ).all (
1779
+ axis = 1
1780
+ )
1767
1781
obj ._metadata = obj ._metadata [tf ]
1768
1782
1769
1783
# filter by annotations
1770
1784
if annotations :
1771
- _annotations = pd .json_normalize (obj ._metadata [' annotations' ])
1785
+ _annotations = pd .json_normalize (obj ._metadata [" annotations" ])
1772
1786
if not _annotations .columns .isin (annotations .keys ()).any ():
1773
1787
raise BTRDBValueError ("annotations key not found" )
1774
- _metadata = obj ._metadata .join (
1775
- _annotations ,
1776
- rsuffix = '_annotations'
1777
- ).drop (columns = ['annotations' ])
1788
+ obj ._metadata = obj ._metadata .join (
1789
+ _annotations , rsuffix = "_annotations"
1790
+ ).drop (columns = ["annotations" ])
1778
1791
1779
- _columns = list (annotations .keys ()) + list (map (lambda s : "" .join ([s ,'_annotations' ]), annotations .keys ()))
1792
+ _columns = list (annotations .keys ()) + list (
1793
+ map (lambda s : "" .join ([s , "_annotations" ]), annotations .keys ())
1794
+ )
1780
1795
# filters if the subset of the annotations matches the given annotations
1781
- tf = (tf
1782
- & obj ._metadata .loc [:, obj ._metadata .columns .isin (_columns )]
1783
- .apply (lambda x : x .str .contains (annotations [x .name ], case = False , regex = False ))
1784
- .all (axis = 1 ))
1796
+ tf = tf & obj ._metadata .loc [:, obj ._metadata .columns .isin (_columns )].apply (
1797
+ lambda x : x .str .contains (annotations [x .name ], case = False , regex = False )
1798
+ ).all (axis = 1 )
1785
1799
obj ._metadata = obj ._metadata [tf ]
1786
- obj ._streams = obj ._metadata [' stream' ]
1800
+ obj ._streams = obj ._metadata [" stream" ]
1787
1801
return obj
1788
1802
1789
1803
def clone (self ):
@@ -2195,7 +2209,7 @@ def arrow_values(
2195
2209
pa .field (str (s .uuid ), pa .float64 (), nullable = False )
2196
2210
for s in self ._streams
2197
2211
],
2198
- )
2212
+ )
2199
2213
data = pa .Table .from_arrays (
2200
2214
[pa .array ([]) for i in range (1 + len (self ._streams ))], schema = schema
2201
2215
)
@@ -2277,4 +2291,4 @@ def _coalesce_table_deque(tables: deque):
2277
2291
main_table = main_table .join (
2278
2292
t2 , "time" , join_type = "full outer" , right_suffix = f"_{ idx } "
2279
2293
)
2280
- return main_table
2294
+ return main_table
0 commit comments