Skip to content

Commit

Permalink
Return an empty dataframe in case the expected file is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
rantahar committed Feb 13, 2024
1 parent 50cbb54 commit 950c5f6
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions niimpy/reading/google_takeout.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import google_takeout_email as email_utils



def format_inferred_activity(data, inferred_activity, activity_threshold):
# Format the activity type column into activity type and
# activity inference confidence. The data is nested a few
Expand Down Expand Up @@ -105,8 +106,12 @@ def location_history(


# Read json data from the zip file and convert to pandas DataFrame.
zip_file = ZipFile(zip_filename)
json_data = zip_file.read("Takeout/Location History/Records.json")
try:
zip_file = ZipFile(zip_filename)
json_data = zip_file.read("Takeout/Location History/Records.json")
except KeyError:
warnings.warn("Could not find location history in zip file.")
return pd.DataFrame()
json_data = json.loads(json_data)
data = pd.json_normalize(json_data["locations"])
data = pd.DataFrame(data)
Expand Down Expand Up @@ -326,7 +331,11 @@ def email_activity(
data : pandas.DataFrame
"""
mailbox = email_file(filename)
try:
mailbox = email_file(filename)
except KeyError:
warnings.warn("Could not find email data in file.")
return pd.DataFrame()

data = []
for message in mailbox.messages:
Expand Down

0 comments on commit 950c5f6

Please sign in to comment.