Skip to content

Commit 0ae8921

Browse files
Merge branch 'main' into feature/multi-format-support
2 parents 71da32b + e13359f commit 0ae8921

File tree

14 files changed

+66
-2
lines changed

14 files changed

+66
-2
lines changed

.gitignore

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
1-
node_modules
1+
node_modules
2+
# Ignore virtual environments
3+
myenv/
4+
venv/
5+
.env
6+
.venv
7+
ENV/
8+
env.bak/
9+
venv.bak/

app/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# i just created this file so python know this directory is package and can import from it (needed to import extract function in root/tests/test_extract.py)
129 Bytes
Binary file not shown.

app/etl/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# i just created this file so python know this directory is package and can import from it (needed to import extract function in root/tests/test_extract.py)
133 Bytes
Binary file not shown.
1.53 KB
Binary file not shown.

app/etl/extract.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ def extract(path: str = "xyz.csv") -> pd.DataFrame:
2828
supported_formats = ['.csv', '.xlsx', '.xls', '.json']
2929
if file_ext not in supported_formats:
3030
raise ValueError(f"❌ Unsupported file format: {file_ext}. Supported formats: {supported_formats}")
31+
if not str(path).lower().endswith('.csv'):
32+
raise ValueError(f"❌ File must be a CSV: {path}")
3133

3234
try:
3335
df = None
@@ -64,12 +66,18 @@ def extract(path: str = "xyz.csv") -> pd.DataFrame:
6466
try:
6567
df = pd.read_json(path)
6668
print(f"Successfully read JSON file: {path}")
69+
# TODO (Find & Fix)
70+
pass
71+
except UnicodeDecodeError:
72+
print(f"Failed to read with encoding '{encoding}'") # Log the encoding that failed
73+
continue
6774
except Exception as e:
6875
raise ValueError(f"❌ Error reading JSON file: {e}")
6976

7077
# Validate data
7178
if df is None:
7279
raise ValueError("❌ Failed to read data from file")
80+
raise ValueError(f"Could not read CSV with tried encodings: {encodings}")
7381

7482
if df.empty:
7583
raise ValueError(" File contains no data")
@@ -82,4 +90,5 @@ def extract(path: str = "xyz.csv") -> pd.DataFrame:
8290
except pd.errors.ParserError as e:
8391
raise ValueError(f"❌ Error parsing file: {e}")
8492
except Exception as e:
85-
raise ValueError(f"❌ Unexpected error reading file: {e}")
93+
raise ValueError(f"❌ Unexpected error reading file: {e}")
94+
raise ValueError(f"❌ Error parsing CSV: {e}")

tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# i just created this file so python know this directory is package and can import from it (needed to import extract function in root/tests/test_extract.py)
131 Bytes
Binary file not shown.
2.32 KB
Binary file not shown.

0 commit comments

Comments
 (0)