Skip to content

Commit

Permalink
Merge pull request #44 from pnnl/fix_preprocess_api_init
Browse files Browse the repository at this point in the history
Fix preprocessing API initialization
  • Loading branch information
leijerry888 authored Jul 19, 2024
2 parents 573cfff + 5cd8407 commit 5f738b7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
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":
# 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":
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)

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

0 comments on commit 5f738b7

Please sign in to comment.