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

Importing JSON Array #4

Merged
merged 1 commit into from
Jun 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/pySupersetCli/cmd_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import os
import argparse
import logging
import json
import pandas as pd
from pySupersetCli.ret import Ret
from pySupersetCli.superset import Superset
Expand Down Expand Up @@ -125,14 +126,16 @@ def _execute(args, superset_client: Superset) -> Ret:
"Invalid file format. Please provide a JSON file.")

with open(args.file, encoding="utf-8") as json_file:
# Input is a dictionary, with keys as index
data_frame = pd.read_json(json_file, orient='index')
data_dict = json.load(json_file)

if DATE_COLUMN not in data_frame:
if DATE_COLUMN not in data_dict:
raise ValueError(
"No 'date' column found in the JSON file.")

# pylint: disable=no-member
# Pack the JSON data into a Pandas DataFrame.
data_frame = pd.DataFrame([data_dict])

# Write the DataFrame to a temporary CSV file.
data_frame.to_csv(_TEMP_FILE_NAME, encoding="UTF-8", index=False)

with open(_TEMP_FILE_NAME, 'rb') as csv_file:
Expand Down