Skip to content

Commit

Permalink
General enhancements
Browse files Browse the repository at this point in the history
1. Removed any returns for '__init__' at model.py
2. Function 'export_as_sql' patched for returning 'state', and 'imported content' instead of 'content' at model.py
3. Removed un-used libraries at index.py
4. File structure adjustments (removed src folder)
5. Functions documentation updates at model.py
6. Minor comments adjustments at index.py, and model.py
  • Loading branch information
throughamad committed Aug 6, 2024
1 parent 332ac8b commit e10ea5f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
3 changes: 1 addition & 2 deletions src/index.py → index.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import pandas as pd
from model import convertor

def main():

dataframe = convertor(filePath="Your File Path")
dataframe = convertor(filePath="assets/RTA Dataset.csv") # Dataframe Example

if __name__ == "__main__":
main()
13 changes: 5 additions & 8 deletions src/model.py → model.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class convertor:
including cleaning, data type conversion, and exporting.
"""

def __init__(self, filePath:str = "C:/file/path/here") -> None:
def __init__(self, filePath:str = "C:/file/path/here.csv") -> None:
"""
Initialize the class with the path to a CSV file and load it into a dataframe.
Expand All @@ -21,8 +21,6 @@ def __init__(self, filePath:str = "C:/file/path/here") -> None:
self.dataframe = pd.read_csv(filePath, encoding='latin-1')
except FileNotFoundError:
print("File Not Found | The provided filepath is invalid")
except Exception:
return None
else:
print("File has been read successfully!")

Expand All @@ -35,12 +33,12 @@ def getDataframe(self) -> DataFrame:
"""
return self.dataframe

def getInfo(self):
def getInfo(self) -> str:
"""
Print a concise summary of the dataframe.
Returns:
None
String: Summary of the dataframe
"""
return self.getDataframe().info()

Expand Down Expand Up @@ -120,7 +118,6 @@ def convertDataType(self, attr: str, dataType: str) -> tuple:
except UserWarning:
return False, f"An error occurred while processing datatype options"
else:
# Converting the datatype of that selected column
try:
self.dataframe = self.dataframe.astype({
f'{attr}': f'{dataType.lower()}'
Expand Down Expand Up @@ -207,7 +204,7 @@ def data_sql_modifier(self, table_name:str = 'tableXyz', output:int = 2) -> tupl
if processed_columns != fetched_columns:
raise UserWarning
else:
print(f'| Processed columns: {processed_columns}\n| Fetched columns: {fetched_columns}')
print(f'| Processed columns: {processed_columns}\n| Fetched columns: {fetched_columns}') # to verify fetching process is successful
except UserWarning:
return False, f"An error occurred while validating the fetched datatypes of the selected dataframe | Not all columns are fetched, some are missing" # edit the return message
except Exception as e:
Expand Down Expand Up @@ -264,7 +261,7 @@ def export_as_mysql(self, table_name:str = 'tableXyz', output:int = 2, path:str
if state == False:
raise UserWarning
except UserWarning:
state, content
state, imported_content
else:
try:
file = open(path + ".txt", "w")
Expand Down
File renamed without changes.

0 comments on commit e10ea5f

Please sign in to comment.