Skip to content

Commit

Permalink
Let examples work in smoke test
Browse files Browse the repository at this point in the history
In the smoke test, "os.path.abspath(__file__)" will give the path of the
smoke test. Thus, loading files has to consider this.
  • Loading branch information
p-snft committed Jan 22, 2025
1 parent 6e0a757 commit a624005
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
7 changes: 5 additions & 2 deletions examples/basic_example/basic_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,11 @@


def get_data_from_file_path(file_path: str) -> pd.DataFrame:
dir = os.path.dirname(os.path.abspath(__file__))
data = pd.read_csv(dir + "/" + file_path)
try:
data = pd.read_csv(file_path)
except FileNotFoundError:
dir = os.path.dirname(os.path.abspath(__file__))
data = pd.read_csv(dir + "/" + file_path)
return data


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@
plt = None


def get_data_from_file_path(file_path: str) -> pd.DataFrame:
try:
data = pd.read_csv(file_path)
except FileNotFoundError:
dir = os.path.dirname(os.path.abspath(__file__))
data = pd.read_csv(dir + "/" + file_path)
return data


def offset_converter_example():
##########################################################################
# Initialize the energy system and calculate necessary parameters
Expand All @@ -84,9 +93,7 @@ def offset_converter_example():
end_datetime = start_datetime + timedelta(days=n_days)

# Import data.
current_directory = os.path.dirname(os.path.abspath(__file__))
filename = os.path.join(current_directory, "diesel_genset_data.csv")
data = pd.read_csv(filepath_or_buffer=filename)
data = get_data_from_file_path("diesel_genset_data.csv")

# Change the index of data to be able to select data based on the time range.
data.index = pd.date_range(start="2022-01-01", periods=len(data), freq="h")
Expand Down

0 comments on commit a624005

Please sign in to comment.