Skip to content

Commit

Permalink
Merge pull request #4 from NewTec-GmbH/dev
Browse files Browse the repository at this point in the history
Importing JSON Array
  • Loading branch information
gabryelreyes authored Jun 28, 2024
2 parents d5b3151 + 4f8e657 commit 911394d
Showing 1 changed file with 7 additions and 4 deletions.
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

0 comments on commit 911394d

Please # to comment.