Skip to content

Commit

Permalink
#591: load parquet from UI
Browse files Browse the repository at this point in the history
  • Loading branch information
aschonfeld committed Oct 31, 2021
1 parent 73a8148 commit b6b6beb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
16 changes: 13 additions & 3 deletions dtale/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
dict_merge,
divide_chunks,
export_to_csv_buffer,
export_to_parquet_buffer,
find_dtype,
find_dtype_formatter,
format_grid,
Expand Down Expand Up @@ -2542,6 +2541,8 @@ def data_export(data_id):
filename = build_chart_filename("data", ext=file_type)
return send_file(csv_buffer.getvalue(), filename, "text/{}".format(file_type))
elif file_type == "parquet":
from dtale.utils import export_to_parquet_buffer

parquet_buffer = export_to_parquet_buffer(data)
filename = build_chart_filename("data", ext="parquet.gzip")
return send_file(
Expand Down Expand Up @@ -3259,6 +3260,9 @@ def build_xls_code(sheet_name):
for sheet_name, df in dfs.items()
}
return handle_excel_upload(dfs)
if "parquet" in filename:
df = pd.read_parquet(contents)
return load_new_data(df, "df = pd.read_parquet('{}')".format(filename))
raise Exception("File type of {} is not supported!".format(ext))


Expand All @@ -3268,6 +3272,7 @@ def web_upload():
from dtale.cli.loaders.csv_loader import loader_func as load_csv
from dtale.cli.loaders.json_loader import loader_func as load_json
from dtale.cli.loaders.excel_loader import load_file as load_excel
from dtale.cli.loaders.parquet_loader import loader_func as load_parquet

data_type = get_str_arg(request, "type")
url = get_str_arg(request, "url")
Expand All @@ -3288,7 +3293,7 @@ def web_upload():
df = load_json(path=url, proxy=proxy)
startup_code = (
"from dtale.cli.loaders.json_loader import loader_func as load_json\n\n"
"df = load_csv(path='{url}'{proxy})"
"df = load_json(path='{url}'{proxy})"
).format(url=url, proxy=", '{}'".format(proxy) if proxy else "")
elif data_type == "excel":
dfs = load_excel(path=url, proxy=proxy)
Expand All @@ -3308,7 +3313,12 @@ def build_xls_code(sheet_name):
for sheet_name, df in dfs.items()
}
return handle_excel_upload(dfs)

elif data_type == "parquet":
df = load_parquet(path=url)
startup_code = (
"from dtale.cli.loaders.parquet_loader import loader_func as load_parquet\n\n"
"df = load_parquet(path='{url}'{proxy})"
).format(url=url, proxy=", '{}'".format(proxy) if proxy else "")
return load_new_data(df, startup_code)


Expand Down
11 changes: 6 additions & 5 deletions static/popups/upload/Upload.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,11 @@ class ReactUpload extends React.Component {
className: "filepicker dropzone dz-clickable",
})}>
<input {...getInputProps()} name="file" />
<div data-filetype=".csv" className="filepicker-file-icon"></div>
<div data-filetype=".tsv" className="filepicker-file-icon"></div>
<div data-filetype=".xls" className="filepicker-file-icon"></div>
<div data-filetype=".xlsx" className="filepicker-file-icon"></div>
<div data-filetype=".csv" className="filepicker-file-icon" />
<div data-filetype=".tsv" className="filepicker-file-icon" />
<div data-filetype=".xls" className="filepicker-file-icon" />
<div data-filetype=".xlsx" className="filepicker-file-icon" />
<div data-filetype=".parquet" className="filepicker-file-icon" />
<div className="dz-default dz-message">
<span>{t("Drop data files here to upload, or click to select files")}</span>
</div>
Expand Down Expand Up @@ -191,7 +192,7 @@ class ReactUpload extends React.Component {
<label className="col-md-3 col-form-label text-right">{t("Data Type")}</label>
<div className="col-md-8 p-0">
<div className="btn-group">
{_.map(["csv", "tsv", "json", "excel"], urlDataType => {
{_.map(["csv", "tsv", "json", "excel", "parquet"], urlDataType => {
const buttonProps = { className: "btn btn-primary" };
if (urlDataType === this.state.urlDataType) {
buttonProps.className += " active";
Expand Down

0 comments on commit b6b6beb

Please sign in to comment.