def test_bus_display_a(self) -> None: f1 = Frame.from_dict( dict(a=(1,2), b=(3,4)), index=('x', 'y'), name='f1') f2 = Frame.from_dict( dict(c=(1,2,3), b=(4,5,6)), index=('x', 'y', 'z'), name='f2') f3 = Frame.from_dict( dict(d=(10,20), b=(50,60)), index=('p', 'q'), name='f3') b1 = Bus.from_frames((f1, f2, f3)) self.assertEqual( b1.display(config=DisplayConfig(type_color=False)).to_rows(), ['<Bus>', '<Index>', 'f1 Frame', 'f2 Frame', 'f3 Frame', '<<U2> <object>']) rows1 = b1.display(config=DisplayConfig( type_color=False, type_show=False)).to_rows() self.assertEqual(rows1, ['f1 Frame', 'f2 Frame', 'f3 Frame']) rows2 = b1.display(config=DisplayConfig( type_color=False, type_show=False, include_index=False)).to_rows() self.assertEqual(rows2, ['Frame', 'Frame', 'Frame'])
def get(**kwargs: tp.Union[bool, int, str]) -> DisplayConfig: config: DisplayConfig = _module._display_active # type: ignore if not kwargs: return config args = config.to_dict() args.update(kwargs) return DisplayConfig(**args)
def display(self, config: tp.Optional[DisplayConfig] = None, *, style_config: tp.Optional[StyleConfig] = None, ) -> Display: '''{doc} Args: {config} ''' if self._assign_axis: self._update_axis_labels() drop_column_dtype = False if self._axis == 0: if not self._retain_labels: index = self.index.rename("Concatenated") else: index = self._bus.index.rename("Frames") columns = self.columns.rename("Aligned") else: index = self.index.rename("Aligned") if not self._retain_labels: columns = self.columns.rename("Concatenated") else: columns = self._bus.index.rename("Frames") drop_column_dtype = True config = config or DisplayConfig() def placeholder_gen() -> tp.Iterator[tp.Iterable[tp.Any]]: assert config is not None yield from repeat(tuple(repeat(config.cell_placeholder, times=len(index))), times=len(columns)) d = Display.from_params( index=index, columns=columns, header=DisplayHeader(self.__class__, self.name), column_forward_iter=placeholder_gen, column_reverse_iter=placeholder_gen, column_default_iter=placeholder_gen, config=config, style_config=style_config, ) # Strip out the dtype information! if config.type_show: if drop_column_dtype: # First Column Row -> last element is the dtype of the column # Guaranteed to not be index hierarchy as buses cannot have index hierarchies d._rows[1].pop() # Since placeholder_gen is not a ndarray, there is no dtype to append in the final row # However, in the case of a center ellipsis being added, an ellipsis will be # awkwardly placed direclty adjacent to the index dtype information. if d._rows[-1][-1] == Display.CELL_ELLIPSIS: d._rows[-1].pop() return d
def test_batch_shapes_a(self) -> None: dc = DisplayConfig.from_default(type_color=False) f1 = Frame.from_dict({'a':[1,2,3], 'b':[2,4,6], 'group': ['x','z','z']}) b1 = Batch(f1.iter_group_items('group'))[['a', 'b']] self.assertEqual(b1.shapes.to_pairs(), (('x', (1, 2)), ('z', (2, 2))) )
def test_batch_display_a(self) -> None: dc = DisplayConfig.from_default(type_color=False) f1 = Frame.from_dict({'a':[1,2,3], 'b':[2,4,6], 'group': ['x','z','z']}) gi = f1.iter_group_items('group') d1 = Batch(gi)[['a', 'b']].display(dc) self.assertEqual(d1.to_rows(), ['<Batch>', '<Index>', 'x <Frame>', 'z <Frame>', '<<U1> <object>' ])
def display_wide(self, config: tp.Optional[DisplayConfig] = None) -> Display: '''Maximize horizontal presentation. {doc} Args: {config} ''' config = config or DisplayActive.get() args = config.to_dict() args.update( dict( display_columns=np.inf, cell_max_width=np.inf, cell_max_width_leftmost=np.inf, )) return self.display(config=DisplayConfig(**args))
def test_yarn_display_a(self) -> None: f1 = ff.parse('s(4,2)').rename('f1') f2 = ff.parse('s(4,5)').rename('f2') f3 = ff.parse('s(2,2)').rename('f3') f4 = ff.parse('s(2,8)').rename('f4') f5 = ff.parse('s(4,4)').rename('f5') f6 = ff.parse('s(6,4)').rename('f6') b1 = Bus.from_frames((f1, f2, f3), name='a') b2 = Bus.from_frames((f4, f5, f6), name='b') y1 = Yarn.from_buses((b1, b2), retain_labels=False) d = y1.display(DisplayConfig(type_show=True, type_color=False)) self.assertEqual(d.to_rows(), ['<Yarn>', '<Index>', 'f1 Frame', 'f2 Frame', 'f3 Frame', 'f4 Frame', 'f5 Frame', 'f6 Frame', '<<U2> <object>'])
def read(cls, fp: tp.Optional[str] = None) -> None: fp = fp or cls._default_fp() cls.set(DisplayConfig.from_file(fp))
def update(cls, **kwargs: object) -> None: args = cls.get().to_dict() args.update(kwargs) cls.set(DisplayConfig(**args))
return False #pragma: no cover if getattr(stream, 'closed', False): # if has closed attr and closed return False #pragma: no cover if hasattr( stream, 'isatty') and stream.isatty() and platform.system() != 'Windows': return True #pragma: no cover return False #------------------------------------------------------------------------------- _module._display_active = DisplayConfig() # type: ignore class DisplayActive: '''Utility interface for setting module-level display configuration. ''' FILE_NAME = '.static_frame.conf' @staticmethod def set(dc: DisplayConfig) -> None: _module._display_active = dc # type: ignore @staticmethod def get(**kwargs: tp.Union[bool, int, str]) -> DisplayConfig: config: DisplayConfig = _module._display_active # type: ignore if not kwargs: