Exemple #1
0
 def add_child(self,
               instance: Child,
               reset: bool = False,
               inplace: bool = False) -> Context:
     name = instance.get_name()
     err_msg = 'instance with name {} already registered (got {})'
     if ct.is_conn(instance):
         assert reset or name not in self.conn_instances, err_msg.format(
             name, instance)
         self.conn_instances[name] = instance
     elif sm.is_stream(instance):
         assert reset or name not in self.stream_instances, err_msg.format(
             name, instance)
         self.stream_instances[name] = instance
     elif lg.is_logger(instance):
         assert isinstance(instance, lg.LoggerInterface)
         if hasattr(instance, 'is_common_logger'):
             if instance.is_common_logger():
                 self.set_logger(instance)
     elif hasattr(instance, 'is_progress'):
         pass
     else:
         raise TypeError("class {} isn't supported by context".format(
             instance.__class__.__name__))
     if not instance.get_context():
         instance.set_context(self)
     if not inplace:
         return self
Exemple #2
0
def _stream(data: Data) -> sm.RecordStream:
    if hasattr(data, 'is_file'):
        if data.is_file():
            if hasattr(data, 'to_record_stream'):
                return data.to_record_stream()
    if sm.is_stream(data):
        stream = data
    else:
        stream = sm.RecordStream(data, check=False)
    return stream
Exemple #3
0
 def add(self,
         dataframe_or_stream_or_items,
         before: bool = False,
         **kwargs) -> Native:
     assert not kwargs, 'kwargs for PandasStream.add() not supported'
     if isinstance(dataframe_or_stream_or_items, DataFrame):
         return self.add_dataframe(dataframe_or_stream_or_items, before)
     elif isinstance(
             dataframe_or_stream_or_items,
             StreamInterface) or sm.is_stream(dataframe_or_stream_or_items):
         return self.add_stream(dataframe_or_stream_or_items, before)
     elif isinstance(dataframe_or_stream_or_items, Iterable):
         return self.add_items(dataframe_or_stream_or_items)
     else:
         msg = 'dataframe_or_stream_or_items must be DataFrame, Stream or Iterable, got {}'
         raise TypeError(msg.format(dataframe_or_stream_or_items))
Exemple #4
0
 def stream(self,
            stream_type: Union[StreamType, Stream, Name],
            name: Union[Name, Auto] = AUTO,
            check: bool = True,
            **kwargs) -> Stream:
     name = Auto.acquire(name, get_generated_name('Stream'))
     if sm.is_stream(stream_type):
         stream_object = stream_type
     else:
         stream_object = sm.stream(stream_type, **kwargs)
     stream_object = stream_object.set_name(
         name,
         register=False,
     ).fill_meta(context=self, check=check, **self.stream_config)
     self.stream_instances[name] = stream_object
     return stream_object