Example #1
0
    def test_work_with_parquet(self):
        filename = encode_token(
            os.path.dirname(inspect.getfile(self.__class__)) + "/test.csv")
        with TemporaryDirectory() as tmpdir:
            path = Path(tmpdir) / "test.parquet"
            evaluate_and_save(f"df_from-{filename}/test.parquet",
                              target_directory=tmpdir)

            @first_command(volatile=True, cache=False)
            def execution_context():
                ctx = daf.ExecutionContext()
                ctx.register_parquet("a", str(path))
                return ctx

            @command
            def process(ctx):
                return ctx.sql("SELECT a, b, a+b AS c FROM a")

            evaluate_and_save(f"execution_context/process/result.parquet",
                              target_directory=tmpdir)

            df = evaluate(
                f"execution_context/process/datafusion_to_pandas").get()
            assert "a" in df.columns
            assert "b" in df.columns
            assert "c" in df.columns
            assert list(df.a) == [1, 3]
            assert list(df.b) == [2, 4]
            assert list(df.c) == [3, 7]
Example #2
0
    def test_image(self):
        store = MemoryStore()
        set_store(store)

        @first_command
        def image():
            return Image.new(mode="RGB", size=(200, 300))

        assert evaluate("image").get().size == (200,300)
        evaluate_and_save("image/ns-pil/resize-400-600-bilinear/test.png",target_resource_directory="x")
        image = evaluate("x/test.png/-/dr").get()
        assert image.size == (400,600)
Example #3
0
    def test_workbook(self):
        store = MemoryStore()
        set_store(store)

        filename = encode_token(
            os.path.dirname(inspect.getfile(self.__class__)) + "/test.csv")
        evaluate_and_save(f"df_from-{filename}/test.xlsx",
                          target_resource_directory="testdir")
        df = evaluate("testdir/test.xlsx/-/workbook/workbook_sheet_df").get()
        assert "a" in df.columns
        assert "b" in df.columns
        assert list(df.a) == [1, 3]
        assert list(df.b) == [2, 4]
Example #4
0
    def test_pptx(self):
        store = MemoryStore()
        set_store(store)

        @first_command
        def make_presentation():
            prs = Presentation()
            title_slide_layout = prs.slide_layouts[0]
            slide = prs.slides.add_slide(title_slide_layout)
            title = slide.shapes.title
            subtitle = slide.placeholders[1]

            title.text = "Hello, World!"
            subtitle.text = "python-pptx was here!"
            return prs

        @command
        def add_slide(prs, title="Title"):
            bullet_slide_layout = prs.slide_layouts[1]

            slide = prs.slides.add_slide(bullet_slide_layout)
            shapes = slide.shapes

            title_shape = shapes.title
            body_shape = shapes.placeholders[1]

            title_shape.text = title

            tf = body_shape.text_frame
            tf.text = 'Find the bullet slide layout'

            p = tf.add_paragraph()
            p.text = 'Use _TextFrame.text for first bullet'
            p.level = 1
            return prs

        evaluate_and_save(f"make_presentation/add_slide/test.pptx",
                          target_resource_directory="testdir")
        assert store.get_metadata(
            "testdir/test.pptx")["type_identifier"] == "pptx_presentation"
        prs = evaluate("testdir/test.pptx/-/dr/add_slide-Slide2").get()
        assert len(prs.slides) == 3
Example #5
0
    def test_save_parquet(self):

        filename = encode_token(
            os.path.dirname(inspect.getfile(self.__class__)) + "/test.csv"
        )
        evaluate_and_save(f"df_from-{filename}/polars_df/test.parquet", target_directory=".")
Example #6
0
    def test_save_feather(self):
        import liquer.ext.lq_pandas  # register pandas commands and state type

        filename = encode_token(
            os.path.dirname(inspect.getfile(self.__class__)) + "/test.csv")
        evaluate_and_save(f"df_from-{filename}/head_df-1/test.feather")
Example #7
0
    subtitle = slide.placeholders[1]

    title.text = "Hello, World!"
    subtitle.text = "python-pptx was here!"
    return prs


@command
def add_slide(prs, title="Title"):
    bullet_slide_layout = prs.slide_layouts[1]

    slide = prs.slides.add_slide(bullet_slide_layout)
    shapes = slide.shapes

    title_shape = shapes.title
    body_shape = shapes.placeholders[1]

    title_shape.text = title

    tf = body_shape.text_frame
    tf.text = 'Find the bullet slide layout'

    p = tf.add_paragraph()
    p.text = 'Use _TextFrame.text for first bullet'
    p.level = 1
    return prs


evaluate_and_save(
    f"make_presentation/add_slide-Slide1/add_slide-Slide2/test.pptx")