Skip to content

Commit

Permalink
Remove try-except block
Browse files Browse the repository at this point in the history
  • Loading branch information
dcjohnson24 committed Nov 27, 2023
1 parent 24105a0 commit 3305dd8
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions utils/s3_csv_reader.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import pandas as pd
from pathlib import Path
import botocore
import data_analysis.compare_scheduled_and_rt as csrt

def read_csv(filename: str | Path) -> pd.DataFrame:
"""Read pandas csv from S3 using multiple methods
"""Read pandas csv from S3
Args:
filename (str | Path): file to download from S3.
Expand All @@ -14,13 +13,10 @@ def read_csv(filename: str | Path) -> pd.DataFrame:
"""
if isinstance(filename, str):
filename = Path(filename)
# Use low_memory option to avoid warning about columns with mixed dtypes.
try:
df = pd.read_csv(filename.as_uri(), low_memory=False)
except (botocore.exceptions.ConnectTimeoutError, botocore.exceptions.EndpointConnectionError):
s3_filename = '/'.join(filename.parts[-2:])
df = pd.read_csv(
s3_filename = '/'.join(filename.parts[-2:])
df = pd.read_csv(
f'https://{csrt.BUCKET_PUBLIC}.s3.us-east-2.amazonaws.com/{s3_filename}',
low_memory=False
)
return df
return df

0 comments on commit 3305dd8

Please sign in to comment.