Refactor imports and improve logging in multiple modules; streamline type hints and remove redundant code
This commit is contained in:
+5
-11
@@ -1,7 +1,6 @@
|
||||
import os
|
||||
import csv
|
||||
import logging
|
||||
from typing import List, Union
|
||||
import os
|
||||
|
||||
import pandas as pd
|
||||
|
||||
@@ -36,13 +35,8 @@ class DataManager:
|
||||
|
||||
def load_data(self) -> pd.DataFrame:
|
||||
"""Load data from CSV file."""
|
||||
if (
|
||||
not os.path.exists(self.filename)
|
||||
or os.path.getsize(self.filename) == 0
|
||||
):
|
||||
self.logger.warning(
|
||||
"CSV file is empty or doesn't exist. No data to load."
|
||||
)
|
||||
if not os.path.exists(self.filename) or os.path.getsize(self.filename) == 0:
|
||||
self.logger.warning("CSV file is empty or doesn't exist. No data to load.")
|
||||
return pd.DataFrame()
|
||||
|
||||
try:
|
||||
@@ -69,7 +63,7 @@ class DataManager:
|
||||
self.logger.error(f"Error loading data: {str(e)}")
|
||||
return pd.DataFrame()
|
||||
|
||||
def add_entry(self, entry_data: List[Union[str, int]]) -> bool:
|
||||
def add_entry(self, entry_data: list[str | int]) -> bool:
|
||||
"""Add a new entry to the CSV file."""
|
||||
try:
|
||||
with open(self.filename, mode="a", newline="") as file:
|
||||
@@ -80,7 +74,7 @@ class DataManager:
|
||||
self.logger.error(f"Error adding entry: {str(e)}")
|
||||
return False
|
||||
|
||||
def update_entry(self, date: str, values: List[Union[str, int]]) -> bool:
|
||||
def update_entry(self, date: str, values: list[str | int]) -> bool:
|
||||
"""Update an existing entry identified by date."""
|
||||
try:
|
||||
df: pd.DataFrame = self.load_data()
|
||||
|
||||
Reference in New Issue
Block a user