def _update_object(self, data=None): if self._stream.element is not None: element = self._stream.element if (element.interface.datatype == 'multitabular' and element.data and isinstance(element.data[0], dict)): for path in element.data: for col in self.annotations: if not isscalar(path[col]) and len(path[col]): path[col] = path[col][0] with param.discard_events(self): self.object = element
def validate(self): """Check that inputted path is valid - set validator accordingly""" path = self._new_path(self.path_text) if path and path.is_dir(): self.path = path self.file_listing = [] elif path and path.is_file(): with param.discard_events(self): self.path = path.parent self.file_listing = [path.name] else: logger.warning(f'Invalid Directory: {path}') self.make_options()
def update_version_profiles(self): version = None if self.version == 'System Default' else self.version profiles = self.get_profiles(version=version) version_default = self.get_default_profile( version=self.version, use_general_default=version is None) self.param.environment_profile_version.objects = profiles with param.discard_events(self): self.environment_profile_version = version_default if profiles: self.param.environment_profile_version.precedence = 2 if 'hidden' not in self.no_version_profiles_alert.css_classes: self.no_version_profiles_alert.css_classes.append('hidden') else: self.param.environment_profile_version.precedence = -1 if 'hidden' in self.no_version_profiles_alert.css_classes: self.no_version_profiles_alert.css_classes.remove('hidden')
def stream(self, stream_value, rollover=None, reset_index=True): """ Streams (appends) the `stream_value` provided to the existing value in an efficient manner. Arguments --------- stream_value (Union[pd.DataFrame, pd.Series, Dict]) The new value(s) to append to the existing value. rollover: int A maximum column size, above which data from the start of the column begins to be discarded. If None, then columns will continue to grow unbounded. reset_index (bool, default=True): If True and the stream_value is a DataFrame, then its index is reset. Helps to keep the index unique and named `index` Raises ------ ValueError: Raised if the stream_value is not a supported type. Examples -------- Stream a Series to a DataFrame >>> value = pd.DataFrame({"x": [1, 2], "y": ["a", "b"]}) >>> tabulator = Tabulator(value=value) >>> stream_value = pd.Series({"x": 4, "y": "d"}) >>> tabulator.stream(stream_value) >>> tabulator.value.to_dict("list") {'x': [1, 2, 4], 'y': ['a', 'b', 'd']} Stream a Dataframe to a Dataframe >>> value = pd.DataFrame({"x": [1, 2], "y": ["a", "b"]}) >>> tabulator = Tabulator(value=value) >>> stream_value = pd.DataFrame({"x": [3, 4], "y": ["c", "d"]}) >>> tabulator.stream(stream_value) >>> tabulator.value.to_dict("list") {'x': [1, 2, 3, 4], 'y': ['a', 'b', 'c', 'd']} Stream a Dictionary row to a DataFrame >>> value = pd.DataFrame({"x": [1, 2], "y": ["a", "b"]}) >>> tabulator = Tabulator(value=value) >>> stream_value = {"x": 4, "y": "d"} >>> tabulator.stream(stream_value) >>> tabulator.value.to_dict("list") {'x': [1, 2, 4], 'y': ['a', 'b', 'd']} Stream a Dictionary of Columns to a Dataframe >>> value = pd.DataFrame({"x": [1, 2], "y": ["a", "b"]}) >>> tabulator = Tabulator(value=value) >>> stream_value = {"x": [3, 4], "y": ["c", "d"]} >>> tabulator.stream(stream_value) >>> tabulator.value.to_dict("list") {'x': [1, 2, 3, 4], 'y': ['a', 'b', 'c', 'd']} """ import pandas as pd value_index_start = self.value.index.max() + 1 if isinstance(stream_value, pd.DataFrame): if reset_index: stream_value = stream_value.reset_index(drop=True) stream_value.index += value_index_start combined = pd.concat([self.value, stream_value]) if rollover is not None: combined = combined.iloc[-rollover:] with param.discard_events(self): self.value = combined try: self._updating = True self.param.trigger('value') finally: self._updating = False stream_value = self._filter_dataframe(stream_value) try: self._updating = True self._stream(stream_value, rollover) finally: self._updating = False elif isinstance(stream_value, pd.Series): self.value.loc[value_index_start] = stream_value if rollover is not None and len(self.value) > rollover: with param.discard_events(self): self.value = self.value.iloc[-rollover:] stream_value = self._filter_dataframe(self.value.iloc[-1:]) try: self._updating = True self._stream(stream_value, rollover) finally: self._updating = False elif isinstance(stream_value, dict): if stream_value: try: stream_value = pd.DataFrame(stream_value) except ValueError: stream_value = pd.Series(stream_value) self.stream(stream_value, rollover) else: raise ValueError( "The stream value provided is not a DataFrame, Series or Dict!" )
def widgetUpdater(w, dictValues): with param.discard_events(w): w.param.set_param(**dictValues)
def _update_object(self, data=None): with param.discard_events(self): self.object = self._stream.element
def _update(self, event=None): if event and event.name == 'object': with param.discard_events(self): self.object = self._process_element(event.new) self._update_table()
def stream(self, stream_value, rollover=None, reset_index=True): """ Streams (appends) the `stream_value` provided to the existing value in an efficient manner. Arguments --------- stream_value: (Union[pd.DataFrame, pd.Series, Dict]) The new value(s) to append to the existing value. rollover: int A maximum column size, above which data from the start of the column begins to be discarded. If None, then columns will continue to grow unbounded. reset_index (bool, default=True): If True and the stream_value is a DataFrame, then its index is reset. Helps to keep the index unique and named `index`. Raises ------ ValueError: Raised if the stream_value is not a supported type. Examples -------- Stream a Series to a DataFrame >>> value = pd.DataFrame({"x": [1, 2], "y": ["a", "b"]}) >>> obj = DataComponent(value) >>> stream_value = pd.Series({"x": 4, "y": "d"}) >>> obj.stream(stream_value) >>> obj.value.to_dict("list") {'x': [1, 2, 4], 'y': ['a', 'b', 'd']} Stream a Dataframe to a Dataframe >>> value = pd.DataFrame({"x": [1, 2], "y": ["a", "b"]}) >>> obj = DataComponent(value) >>> stream_value = pd.DataFrame({"x": [3, 4], "y": ["c", "d"]}) >>> obj.stream(stream_value) >>> obj.value.to_dict("list") {'x': [1, 2, 3, 4], 'y': ['a', 'b', 'c', 'd']} Stream a Dictionary row to a DataFrame >>> value = pd.DataFrame({"x": [1, 2], "y": ["a", "b"]}) >>> tabulator = DataComponent(value) >>> stream_value = {"x": 4, "y": "d"} >>> obj.stream(stream_value) >>> obj.value.to_dict("list") {'x': [1, 2, 4], 'y': ['a', 'b', 'd']} Stream a Dictionary of Columns to a Dataframe >>> value = pd.DataFrame({"x": [1, 2], "y": ["a", "b"]}) >>> obj = DataComponent(value) >>> stream_value = {"x": [3, 4], "y": ["c", "d"]} >>> obj.stream(stream_value) >>> obj.value.to_dict("list") {'x': [1, 2, 3, 4], 'y': ['a', 'b', 'c', 'd']} """ if 'pandas' in sys.modules: import pandas as pd else: pd = None if pd and isinstance(stream_value, pd.DataFrame): if isinstance(self._processed, dict): self.stream(stream_value.to_dict(), rollover) return value_index_start = self._processed.index.max() + 1 if reset_index: stream_value = stream_value.reset_index(drop=True) stream_value.index += value_index_start combined = pd.concat([self._processed, stream_value]) if rollover is not None: combined = combined.iloc[-rollover:] with param.discard_events(self): self._update_data(combined) try: self._updating = True self.param.trigger('value') finally: self._updating = False try: self._updating = True self._stream(stream_value, rollover) finally: self._updating = False elif pd and isinstance(stream_value, pd.Series): if isinstance(self._processed, dict): self.stream({k: [v] for k, v in stream_value.to_dict().items()}, rollover) return self._processed.loc[value_index_start] = stream_value with param.discard_events(self): self._update_data(self._processed) self._updating = True try: self._stream(self.value.iloc[-1:], rollover) finally: self._updating = False elif isinstance(stream_value, dict): if isinstance(self._processed, dict): if not all(col in stream_value for col in self._data): raise ValueError("Stream update must append to all columns.") for col, array in stream_value.items(): combined = np.concatenate([self._data[col], array]) if rollover is not None: combined = combined[-rollover:] self._update_column(col, combined) self._updating = True try: self._stream(stream_value, rollover) finally: self._updating = False else: try: stream_value = pd.DataFrame(stream_value) except ValueError: stream_value = pd.Series(stream_value) self.stream(stream_value) else: raise ValueError("The stream value provided is not a DataFrame, Series or Dict!")
def _update_object(self, data=None): with param.discard_events(self): if len(self._stream.source) == 0: self.plot[()] self.object = self._stream.element
def _process_event(self, event): with edit_readonly(self): self.value = event.key with param.discard_events(self): self.value = ""