Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix preprocessing API initialization #44

Merged
merged 3 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions constrain/api/data_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def __init__(
data_source (str): Data source name. Use `EnergyPlus` or `Other`.
timestamp_column_name (str): Name of the column header that contains the time series timestamps.
"""

self.data = None

if data_path is None:
Expand All @@ -44,13 +43,13 @@ def __init__(
# check if data file exists
if os.path.isfile(data_path):
try:
if data_source == "EnergyPlus":
if data_source.lower() == "energyplus":
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No point in doing a case sensitive check.

# Use CSVReader to parse EnergyPlus timestamps
data = CSVReader(csv_file=data_path).getseries()
data = DateTimeEP(data, 2000).transform()
data.drop("Date/Time", inplace=True, axis=1)

elif data_source == "Other":
elif data_source.lower() == "bms":
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Other" seemed to synonymous with an "else" statement, the intent here is to deal with data from BMS.

if timestamp_column_name is None:
logging.error(
"timestamp_column_name is required when data_source = 'Other'"
Expand All @@ -65,7 +64,7 @@ def __init__(
return None
data.set_index(timestamp_column_name, inplace=True)
try:
data = pd.to_datetime(data.index)
data.index = pd.to_datetime(data.index)
except:
logging.error(
f"The data in {timestamp_column_name} could not be converted to Python datetime object. Make sure that the data is consistent defined as a set of date strings."
Expand Down
2 changes: 2 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
# The full version, including alpha/beta/rc tags
release = "0.4.0"

# Document class docstrings
autoclass_content = "both"

# -- General configuration ---------------------------------------------------

Expand Down
14 changes: 8 additions & 6 deletions tests/api/test_data_processing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import unittest, sys, datetime, copy
import unittest, sys, datetime, copy, pandas

import matplotlib

Expand Down Expand Up @@ -76,18 +76,20 @@ def test_ep_data_file(self):
t = DataProcessing(data_path=filep, data_source="EnergyPlus")
assert len(t.data) == 2

def test_other_data_file(self):
def test_BMS_data_file(self):
filep = "./tests/api/data/data_non_ep_head.csv"
dp = DataProcessing(
data_path=filep, data_source="Other", timestamp_column_name="Date Time"
data_path=filep, data_source="BMS", timestamp_column_name="Date Time"
)
assert len(dp.data) == 2
assert len(dp.data.columns) == 106
assert isinstance(dp.data.index, pandas.DatetimeIndex)

Comment on lines +85 to +86
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure that we're getting the expected full dataset.

def test_datafile_error_parsing(self):
with self.assertLogs() as logobs:
filep = "./tests/api/data/data_err_parse.csv"
dp = DataProcessing(
data_path=filep, data_source="Other", timestamp_column_name="Date/Time"
data_path=filep, data_source="BMS", timestamp_column_name="Date/Time"
)
self.assertEqual(
f"ERROR:root:The data in Date/Time could not be converted to Python datetime object. Make sure that the data is consistent defined as a set of date strings.",
Expand All @@ -97,9 +99,9 @@ def test_datafile_error_parsing(self):
def test_datafile_missing_datetimecol(self):
with self.assertLogs() as logobs:
filep = "./tests/api/data/data_non_ep_head.csv"
dp = DataProcessing(data_path=filep, data_source="Other")
dp = DataProcessing(data_path=filep, data_source="BMS")
self.assertEqual(
"ERROR:root:timestamp_column_name is required when data_source = 'Other'",
"ERROR:root:timestamp_column_name is required when data_source = 'BMS'",
logobs.output[0],
)

Expand Down
Loading