Skip to content

Commit

Permalink
Merge pull request #116 from Breakthrough-Energy/jon/requests
Browse files Browse the repository at this point in the history
Fix validation and tox typo
  • Loading branch information
jenhagg authored Oct 15, 2020
2 parents 32677e6 + aeee8aa commit c999c9e
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8]
python-version: [3.7, 3.8]

name: Python ${{ matrix.python-version }}
steps:
Expand Down
21 changes: 14 additions & 7 deletions prereise/gather/solardata/nsrdb/nrel_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,24 @@ class Psm3Data:
data_resource: pd.DataFrame

allowed_attrs = {
"dn": "DNI",
"df": "DHI",
"wspd": "Wind Speed",
"tdry": "Temperature",
"dni": "DNI",
"dhi": "DHI",
"wind_speed": "Wind Speed",
"air_temperature": "Temperature",
"ghi": "GHI",
}

rename_attrs = {
"DHI": "df",
"DNI": "dn",
"Wind Speed": "wspd",
"Temperature": "tdry",
}

@staticmethod
def check_attrs(attributes):
for a in attributes.split(","):
if a not in allowed_attrs.keys():
if a not in Psm3Data.allowed_attrs.keys():
raise ValueError(f"Unsupported attribute: {a}")

def to_dict(self):
Expand All @@ -52,8 +59,8 @@ def to_dict(self):
}
result.update(
{
k: self.data_resource[v].tolist()
for k, v in allowed_attrs.items()
Psm3Data.rename_attrs[v]: self.data_resource[v].tolist()
for v in Psm3Data.allowed_attrs.values()
if v in self.data_resource.columns
}
)
Expand Down
1 change: 1 addition & 0 deletions prereise/gather/solardata/nsrdb/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__all__ = ["test_nrel_api"]
29 changes: 29 additions & 0 deletions prereise/gather/solardata/nsrdb/tests/test_nrel_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from datetime import datetime, timedelta

import pandas as pd
import pytest

from prereise.gather.solardata.nsrdb.nrel_api import Psm3Data


def test_check_attrs():
Psm3Data.check_attrs("dhi,dni,wind_speed,air_temperature,ghi")

with pytest.raises(ValueError):
Psm3Data.check_attrs("foo,bar,dhi")


def test_psm3_to_dict():
date_today = datetime.now()
df = pd.DataFrame(
{
"DNI": [1, 2, 3, 4],
"Wind Speed": [4, 4, 3, 2],
"idx": pd.date_range(date_today, date_today + timedelta(3), freq="D"),
}
)
df.set_index("idx", inplace=True)
psm3 = Psm3Data(1, 2, 8, 8, df)
psm3_dict = psm3.to_dict()
for k in ("tz", "elev", "day", "month", "year", "dn", "wspd"):
assert k in psm3_dict.keys()
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
envlist = pytest-local, format
skipdist = true
skipsdist = true

[testenv]
passenv =
Expand Down

0 comments on commit c999c9e

Please sign in to comment.