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
Exclude None from default_na_values list when reading csv files #374
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
30914b0
Exclude None from default_na list when reading csv files
rajeee 5c0fb19
Update OS version in CI
rajeee eb6b2aa
Validate buildstock.csv
rajeee 21653c8
read buildstock_csv using string dtype
rajeee 1ed82aa
Fix dtype issue
rajeee 75b064d
Update changelog
rajeee fd6f0c8
Fix pandas version to be >2.0
rajeee 4b12209
Update setup.py
nmerket File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,4 @@ coverage/ | |
.coverage | ||
build/ | ||
.env | ||
.history |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,6 @@ | |
import logging | ||
from lxml import objectify | ||
import os | ||
import pandas as pd | ||
import numpy as np | ||
import re | ||
import requests | ||
|
@@ -36,7 +35,7 @@ | |
postprocessing | ||
) | ||
from buildstockbatch.exc import SimulationExists, ValidationError | ||
from buildstockbatch.utils import path_rel_to_file, get_project_configuration | ||
from buildstockbatch.utils import path_rel_to_file, get_project_configuration, read_csv | ||
from buildstockbatch.__version__ import __version__ as bsb_version | ||
|
||
logger = logging.getLogger(__name__) | ||
|
@@ -192,7 +191,7 @@ def cleanup_sim_dir(sim_dir, dest_fs, simout_ts_dir, upgrade_id, building_id): | |
timeseries_filepath = os.path.join(sim_dir, 'run', 'results_timeseries.csv') | ||
# FIXME: Allowing both names here for compatibility. Should consolidate on one timeseries filename. | ||
if os.path.isfile(timeseries_filepath): | ||
units_dict = pd.read_csv(timeseries_filepath, nrows=1).transpose().to_dict()[0] | ||
units_dict = read_csv(timeseries_filepath, nrows=1).transpose().to_dict()[0] | ||
skiprows = [1] | ||
else: | ||
timeseries_filepath = os.path.join(sim_dir, 'run', 'enduse_timeseries.csv') | ||
|
@@ -208,15 +207,15 @@ def cleanup_sim_dir(sim_dir, dest_fs, simout_ts_dir, upgrade_id, building_id): | |
if os.path.isfile(timeseries_filepath): | ||
# Find the time columns present in the enduse_timeseries file | ||
possible_time_cols = ['time', 'Time', 'TimeDST', 'TimeUTC'] | ||
cols = pd.read_csv(timeseries_filepath, index_col=False, nrows=0).columns.tolist() | ||
cols = read_csv(timeseries_filepath, index_col=False, nrows=0).columns.tolist() | ||
actual_time_cols = [c for c in cols if c in possible_time_cols] | ||
if not actual_time_cols: | ||
logger.error(f'Did not find any time column ({possible_time_cols}) in {timeseries_filepath}.') | ||
raise RuntimeError(f'Did not find any time column ({possible_time_cols}) in {timeseries_filepath}.') | ||
|
||
tsdf = pd.read_csv(timeseries_filepath, parse_dates=actual_time_cols, skiprows=skiprows) | ||
tsdf = read_csv(timeseries_filepath, parse_dates=actual_time_cols, skiprows=skiprows) | ||
if os.path.isfile(schedules_filepath): | ||
schedules = pd.read_csv(schedules_filepath, dtype=np.float64) | ||
schedules = read_csv(schedules_filepath, dtype=np.float64) | ||
schedules.rename(columns=lambda x: f'schedules_{x}', inplace=True) | ||
schedules['TimeDST'] = tsdf['Time'] | ||
tsdf = tsdf.merge(schedules, how='left', on='TimeDST') | ||
|
@@ -302,7 +301,7 @@ def validate_openstudio_path(cls, project_file): | |
if os_sha != actual_os_sha: | ||
raise ValidationError( | ||
f"OpenStudio version is correct at {os_version}, but the shas don't match. " | ||
"Got {actual_os_sha}, expected {os_sha}" | ||
f"Got {actual_os_sha}, expected {os_sha}" | ||
) | ||
return True | ||
|
||
|
@@ -315,7 +314,38 @@ def validate_sampler(project_file): | |
except AttributeError: | ||
raise ValidationError(f'Sampler class `{sampler_name}` is not available.') | ||
args = cfg['sampler']['args'] | ||
return Sampler.validate_args(project_file, **args) | ||
Sampler.validate_args(project_file, **args) | ||
if issubclass(Sampler, sampler.PrecomputedSampler): | ||
sample_file = cfg['sampler']['args']['sample_file'] | ||
if not os.path.isabs(sample_file): | ||
sample_file = os.path.join(os.path.dirname(project_file), sample_file) | ||
else: | ||
sample_file = os.path.abspath(sample_file) | ||
buildstock_df = read_csv(sample_file, dtype=str) | ||
BuildStockBatchBase.validate_buildstock_csv(project_file, buildstock_df) | ||
return True | ||
|
||
|
||
@staticmethod | ||
def validate_buildstock_csv(project_file, buildstock_df): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's this doing? Tell me in the changelog. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
param_option_dict, _ = BuildStockBatchBase.get_param_option_dict(project_file) | ||
# verify that all the Columns in buildstock_df only have values available in param_option_dict | ||
# param_option_dict has format: {column_name: [valid_option1, valid_option2, ...], ...} | ||
errors = [] | ||
for column in buildstock_df.columns: | ||
if column in {'Building'}: | ||
continue | ||
if column not in param_option_dict: | ||
errors.append(f'Column {column} in buildstock_csv is not available in options_lookup.tsv') | ||
continue | ||
for option in buildstock_df[column].unique(): | ||
if option not in param_option_dict[column]: | ||
errors.append(f'Option {option} in column {column} of buildstock_csv is not available ' | ||
f'in options_lookup.tsv') | ||
if errors: | ||
raise ValidationError('\n'.join(errors)) | ||
|
||
return True | ||
|
||
@classmethod | ||
def validate_workflow_generator(cls, project_file): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
buildstockbatch/test/test_inputs/test_openstudio_buildstock/resources/buildstock_bad.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Building,Bedroom,Location,Vintage,State,Insulation Wall,Insulation | ||
1,1,AL_Mobile-Rgnl.AP.722230,1940-1950,CO,Good Option,None | ||
2,2,AL_Mobile-Rgnl.AP.722230,1940s,CO,Good Option,None | ||
3,2,AL_Mobile-Rgnl.AP.722230,2010s,VA,Good Option,None | ||
4,2,AL_Mobile-Rgnl.AP.722230,2000s,TX,,None | ||
5,3,AL_Mobile-Rgnl.AP.722230,1970s,VA,,None |
6 changes: 6 additions & 0 deletions
6
buildstockbatch/test/test_inputs/test_openstudio_buildstock/resources/buildstock_good.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Building,Bedroom,Location,Vintage,State,Insulation Wall,Insulation Slab | ||
1,1,AL_Mobile-Rgnl.AP.722230,<1950,CO,Good Option,None | ||
2,3,AL_Mobile-Rgnl.AP.722230,1940s,CO,Good Option,None | ||
3,2,AL_Mobile-Rgnl.AP.722230,2010s,VA,Good Option,None | ||
4,1,AL_Mobile-Rgnl.AP.722230,2000s,VA,Good Option,None | ||
5,2,AL_Mobile-Rgnl.AP.722230,1970s,VA,Good Option,None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the new version of OpenStudio required for this? It looks like @joseph-robertson has updated it in #351 as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, the develop was missing this update to CI so I did it as a part of this PR. Between Joe's and this, whichever PR gets merged last will have to update from develop (or it might be fine since they are exact same changes).