Example #1
0
    def show(self, format=None):
        """show the data object content in Jupyter

        :param format: format to use (when there is no/wrong suffix), e.g. 'png'
        """
        if not is_ipython:
            logger.warning(
                "Jupyter/IPython was not detected, .show() will only display inside Jupyter"
            )
            return

        from IPython import display

        suffix = self.suffix.lower()
        if format:
            suffix = "." + format

        if suffix in [".jpg", ".png", ".gif"]:
            display.display(display.Image(self.get(), format=suffix[1:]))
        elif suffix in [".htm", ".html"]:
            display.display(display.HTML(self.get(encoding="utf-8")))
        elif suffix in [".csv", ".pq", ".parquet"]:
            display.display(self.as_df())
        elif suffix in [".yaml", ".txt", ".py"]:
            display.display(display.Pretty(self.get(encoding="utf-8")))
        elif suffix == ".json":
            display.display(display.JSON(orjson.loads(self.get())))
        elif suffix == ".md":
            display.display(display.Markdown(self.get(encoding="utf-8")))
        else:
            logger.error(f"unsupported show() format {suffix} for {self.url}")
Example #2
0
def test_textdisplayobj_pretty_repr():
    p = display.Pretty("This is a simple test")
    nt.assert_equal(repr(p), '<IPython.core.display.Pretty object>')
    nt.assert_equal(p.data, 'This is a simple test')

    p._show_mem_addr = True
    nt.assert_equal(repr(p), object.__repr__(p))
Example #3
0
def test_textdisplayobj_pretty_repr():
    p = display.Pretty("This is a simple test")
    assert repr(p) == "<IPython.core.display.Pretty object>"
    assert p.data == "This is a simple test"

    p._show_mem_addr = True
    assert repr(p) == object.__repr__(p)