Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Download with Index and Filename parameters #438

Merged
merged 4 commits into from
Feb 2, 2023

Conversation

hoxbro
Copy link
Member

@hoxbro hoxbro commented Jan 31, 2023

This PR does two things:

  • Add the ability to save or not to save the Index
    • Was possible before with kwargs={'index': False}.
    • I have kept it as True to follow the default used by pandas to_xxx methods.
  • Add Filename
    • If this is not defined, it will try self.view.title and thereafter self.view.pipeline.table and clean either of them up to be a valid filename. I have chosen not to do this with the parameter, as a user will expect the actually input to be the filename.

Code used for the filename:

import numpy as np
import pandas as pd
import panel as pn
from lumen.pipeline import Pipeline
from lumen.sources import FileSource
from lumen.views import Table
from lumen.views.base import Download

pn.extension("tabulator")

np.random.seed(1)
df = pd.DataFrame({"revenue": np.random.uniform(0, 10000, 30)})
df.to_parquet("data.parq")

source = FileSource(files=["data.parq"])
pipeline = Pipeline(source=source, table="data", name="Pipeline")

table = Table(
    pipeline=pipeline,
    download=Download(format="csv", index=False, filename="test"),
    # download=Download(format="csv", index=False),
    title="This is my ??test!!!!",
)
table

If it is not used either 'self.view.title' or 'self.view.pipeline.table' will determine the filename.

Both will first go through a cleanup process using Django's slugify
@codecov-commenter
Copy link

codecov-commenter commented Jan 31, 2023

Codecov Report

Merging #438 (369ae81) into main (5475c1a) will increase coverage by 0.07%.
The diff coverage is 82.05%.

@@            Coverage Diff             @@
##             main     #438      +/-   ##
==========================================
+ Coverage   69.25%   69.32%   +0.07%     
==========================================
  Files          76       76              
  Lines        8883     8914      +31     
==========================================
+ Hits         6152     6180      +28     
- Misses       2731     2734       +3     
Impacted Files Coverage Δ
lumen/views/base.py 64.88% <60.00%> (+0.07%) ⬆️
lumen/util.py 68.39% <87.50%> (+0.74%) ⬆️
lumen/tests/views/test_base.py 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Member

@philippjfr philippjfr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you!

@philippjfr philippjfr merged commit d375ffc into main Feb 2, 2023
@philippjfr philippjfr deleted the improve_download branch February 2, 2023 10:27
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants