Example #1
0
    def display(
        self,
        config: tp.Optional[DisplayConfig] = None,
        *,
        style_config: tp.Optional[StyleConfig] = None,
    ) -> Display:
        '''{doc}

        Args:
            {config}
        '''
        # NOTE: the key change over serires is providing the Bus as the displayed class
        config = config or DisplayActive.get()
        display_cls = Display.from_values(
            (),
            header=DisplayHeader(self.__class__, self._series._name),
            config=config)

        array = np.empty(shape=len(self._index), dtype=DTYPE_OBJECT)
        # NOTE: do not load FrameDeferred, so concate contained Series's values directly
        np.concatenate([b._values_mutable for b in self._series.values],
                       out=array)
        array.flags.writeable = False
        series = Series(array, index=self._index, own_index=True)

        return series._display(
            config,
            display_cls=display_cls,
            style_config=style_config,
        )
Example #2
0
    def display(self, config: tp.Optional[DisplayConfig] = None) -> Display:
        config = config or DisplayActive.get()

        if self._recache:
            self._update_array_cache()

        # render display rows just of columns
        # sub_config_type = DisplayConfig(**config.to_dict(type_show=False))
        # sub_config_no_type = DisplayConfig(**config.to_dict(type_show=False))
        sub_config = config
        sub_display = None

        for d in range(self._depth):
            # as a slice this is far more efficient as no copy is made
            col = self._labels[:, d]
            # repeats = col == np.roll(col, 1)
            # repeats[0] = False
            # col[repeats] = '.' # TODO: spacer may not be best
            if sub_display is None:  # the first
                sub_display = Display.from_values(col,
                                                  header=DisplayHeader(
                                                      self.__class__,
                                                      self._name),
                                                  config=sub_config,
                                                  outermost=True,
                                                  index_depth=0,
                                                  columns_depth=1)
            else:
                sub_display.extend_iterable(col, header='')

        return sub_display
Example #3
0
    def display(self, config: tp.Optional[DisplayConfig] = None) -> Display:
        '''Return a Display of the Bus.
        '''
        # NOTE: the key change is providing the Bus as the displayed class

        config = config or DisplayActive.get()

        d = Display([],
                    config=config,
                    outermost=True,
                    index_depth=1,
                    header_depth=2)  # series and index header

        display_index = self._index.display(config=config)
        d.extend_display(display_index)

        d.extend_display(
            Display.from_values(
                self._series.values,  # do not force loading with self.values
                header='',
                config=config))

        display_cls = Display.from_values(
            (),
            header=DisplayHeader(self.__class__, self._series._name),
            config=config)
        d.insert_displays(display_cls.flatten())
        return d
Example #4
0
    def display(self,
            config: tp.Optional[DisplayConfig] = None
            ) -> Display:
        '''Return a Display of the Series.
        '''
        config = config or DisplayActive.get()

        d = Display([],
                config=config,
                outermost=True,
                index_depth=1,
                columns_depth=2) # series and index header

        display_index = self._index.display(config=config)
        d.extend_display(display_index)

        d.extend_display(Display.from_values(
                self.values,
                header='',
                config=config))

        display_cls = Display.from_values((),
                header=DisplayHeader(self.__class__, self._name),
                config=config)
        d.insert_displays(display_cls.flatten())
        return d
Example #5
0
    def display(
        self,
        config: tp.Optional[DisplayConfig] = None,
    ) -> Display:
        '''{doc}

        Args:
            {config}
        '''
        config = config or DisplayActive.get()

        if self._recache:
            self._update_array_cache()

        header: tp.Optional[DisplayHeader]

        if config.type_show:
            header = DisplayHeader(self.__class__, self._name)
            header_depth = 1
        else:
            header = None
            header_depth = 0

        return Display.from_values(
            self.values,
            header=header,
            config=config,
            outermost=True,
            index_depth=0,
            header_depth=header_depth,
        )
Example #6
0
    def display(self, config: DisplayConfig=None) -> Display:
        config = config or DisplayActive.get()

        if self._recache:
            self._update_array_cache()

        # render display rows just of columns
        sub_config = DisplayConfig(**config.to_dict(type_show=False))
        sub_display = None

        for d in range(self._depth):
            # as a slice this is far more efficient as no copy is made
            col = self._labels[:, d]
            # repeats = col == np.roll(col, 1)
            # repeats[0] = False
            # col[repeats] = '.' # TODO: spacer may not be best
            if sub_display is None:
                sub_display = Display.from_values(col,
                        header='',
                        config=sub_config)
            else:
                sub_display.append_iterable(col, header='')

        header = '<' + self.__class__.__name__ + '>'
        return Display.from_values(
                sub_display.to_rows()[1:-1], # truncate unused header
                header = header,
                config=config
                )
Example #7
0
 def _repr_html_(self):
     '''
     Provide HTML representation for Jupyter Notebooks.
     '''
     # modify the active display to be force HTML
     config = DisplayActive.get(display_format=DisplayFormats.HTML_TABLE,
                                type_show=False)
     return repr(self.display(config))
Example #8
0
 def to_html(self, config: tp.Optional[DisplayConfig] = None):
     '''
     {}
     '''
     config = config or DisplayActive.get(type_show=False)
     config = config.to_display_config(
         display_format=DisplayFormats.HTML_TABLE, )
     return repr(self.display(config))
Example #9
0
 def to_html(self):
     '''
     Return an HTML table reprsentation of this Index.
     '''
     config = DisplayActive.get(
             display_format=DisplayFormats.HTML_TABLE,
             type_show=False
             )
     return repr(self.display(config))
Example #10
0
    def display(self, config: DisplayConfig = None) -> Display:
        config = config or DisplayActive.get()

        if self._recache:
            self._update_array_cache()

        return Display.from_values(self.values,
                                   header='<' + self.__class__.__name__ + '>',
                                   config=config)
Example #11
0
 def display_wide(self,
         config: tp.Optional[DisplayConfig] = None
         ) -> Display:
     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))
Example #12
0
    def display(self, config: tp.Optional[DisplayConfig] = None) -> Display:
        config = config or DisplayActive.get()

        items = ((label, f.__class__) for label, f in self._items)
        series = Series.from_items(items, name=self._name)

        display_cls = Display.from_values(
            (),
            header=DisplayHeader(self.__class__, self._name),
            config=config)
        return series._display(config, display_cls)
Example #13
0
    def display(self, config: DisplayConfig = None) -> Display:
        '''Return a Display of the Series.
        '''
        config = config or DisplayActive.get()

        d = self._index.display(config=config)
        d.append_display(
            Display.from_values(self.values,
                                header='<' + self.__class__.__name__ + '>',
                                config=config))
        return d
Example #14
0
    def display(self, config: tp.Optional[DisplayConfig] = None) -> Display:
        '''{doc}

        Args:
            {config}
        '''
        # NOTE: the key change over serires is providing the Bus as the displayed class
        config = config or DisplayActive.get()
        display_cls = Display.from_values(
            (),
            header=DisplayHeader(self.__class__, self._series._name),
            config=config)
        return self._series._display(config, display_cls)
Example #15
0
    def to_html(
        self,
        config: tp.Optional[DisplayConfig] = None,
        style_config: tp.Optional[StyleConfig] = STYLE_CONFIG_DEFAULT,
    ) -> str:
        '''
        {}
        '''
        config = config or DisplayActive.get(type_show=False)
        config = config.to_display_config(
            display_format=DisplayFormats.HTML_TABLE, )

        style_config = style_config_css_factory(style_config, self)
        return repr(self.display(config, style_config=style_config))
Example #16
0
    def _repr_html_(self) -> str:
        '''
        Provide HTML representation for Jupyter Notebooks.
        '''
        # NOTE: We observe that Jupyter will window big content into scrollable component, so do not limit output and introduce ellipsis.

        config = DisplayActive.get(
            display_format=DisplayFormats.HTML_TABLE,
            type_show=False,
            display_columns=np.inf,
            display_rows=np.inf,
        )
        # modify the active display to be for HTML
        return repr(self.display(config))
Example #17
0
    def display(self,
            config: tp.Optional[DisplayConfig] = None,
            ) -> Display:

        config = config or DisplayActive.get()

        if self._recache:
            self._update_array_cache()

        return Display.from_values(self.values,
                header=DisplayHeader(self.__class__, self._name),
                config=config,
                outermost=True,
                index_depth=0,
                columns_depth=1
                )
Example #18
0
    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))
Example #19
0
    def to_html_datatables(self,
                           fp: tp.Optional[FilePathOrFileLike] = None,
                           show: bool = True,
                           config: tp.Optional[DisplayConfig] = None) -> str:
        '''
        {}
        '''
        config = config or DisplayActive.get(type_show=False)
        config = config.to_display_config(
            display_format=DisplayFormats.HTML_DATATABLES, )
        content = repr(self.display(config))
        fp = write_optional_file(content=content, fp=fp)

        if show:
            import webbrowser
            webbrowser.open_new_tab(fp)
        return fp
Example #20
0
    def display(self,
            config: tp.Optional[DisplayConfig]=None,
            ) -> Display:
        # NOTE: deafult index/column is suitable for outermost display.

        config = config or DisplayActive.get()

        if self._recache:
            self._update_array_cache()

        return Display.from_values(self.values,
                header=self.__class__,
                config=config,
                outermost=True,
                index_depth=0,
                columns_depth=1
                )
Example #21
0
    def display(self,
            config: tp.Optional[DisplayConfig]=None
            ) -> Display:
        '''Return a Display of the Series.
        '''
        config = config or DisplayActive.get()

        d = Display([],
                config=config,
                outermost=True,
                index_depth=1,
                columns_depth=1)

        display_index = self._index.display(config=config)
        d.extend_display(display_index)

        d.extend_display(Display.from_values(
                self.values,
                header=self.__class__,
                config=config))
        return d
Example #22
0
    def to_html_datatables(
            self,
            fp: tp.Optional[PathSpecifierOrFileLike] = None,
            *,
            show: bool = True,
            config: tp.Optional[DisplayConfig] = None) -> tp.Optional[str]:
        '''
        {}
        '''
        config = config or DisplayActive.get(type_show=False)
        config = config.to_display_config(
            display_format=DisplayFormats.HTML_DATATABLES, )
        content = repr(self.display(config))
        # path_filter called internally
        fp = write_optional_file(content=content, fp=fp)

        if fp and show:
            import webbrowser  #pragma: no cover
            webbrowser.open_new_tab(fp)  #pragma: no cover

        return fp
Example #23
0
    def display(
        self,
        config: tp.Optional[DisplayConfig] = None,
        *,
        style_config: tp.Optional[StyleConfig] = None,
    ) -> Display:
        '''Provide a :obj:`Series`-style display of the :obj:`Batch`. Note that if the held iterator is a generator, this display will exhaust the generator.
        '''
        config = config or DisplayActive.get()

        items = ((label, f.__class__) for label, f in self._items)
        series = Series.from_items(items, name=self._name)

        display_cls = Display.from_values(
            (),
            header=DisplayHeader(self.__class__, self._name),
            config=config)
        return series._display(
            config,
            display_cls=display_cls,
            style_config=style_config,
        )