8000 Fix code style issues flagged by LGTM by chrisorner · Pull Request #1559 · pvlib/pvlib-python · GitHub
[go: up one dir, main page]

Skip to content

Fix code style issues flagged by LGTM #1559

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

Merged
merged 4 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
fixing issues
  • Loading branch information
Christian Orner committed Sep 27, 2022
commit ac8db0c801fe53392feb7795dc50d4eaf522bb72
1 change: 0 additions & 1 deletion pvlib/forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from pvlib.location import Location
from pvlib.irradiance import campbell_norman, get_extra_radiation, disc
from pvlib.irradiance import _liujordan
from siphon.catalog import TDSCatalog
from siphon.ncss import NCSS

Expand Down
12 changes: 5 additions & 7 deletions pvlib/iam.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,18 +362,16 @@ def martin_ruiz_diffuse(surface_tilt, a_r=0.16, c1=0.4244, c2=None):

beta = np.radians(surface_tilt)

from numpy import pi, sin, cos, exp

# avoid RuntimeWarnings for <, sin, and cos with nan
with np.errstate(invalid='ignore'):
# because sin(pi) isn't exactly zero
sin_beta = np.where(surface_tilt < 90, sin(beta), sin(pi - beta))
sin_beta = np.where(surface_tilt < 90, np.sin(beta), np.sin(np.pi - beta))

trig_term_sky = sin_beta + (pi - beta - sin_beta) / (1 + cos(beta))
trig_term_gnd = sin_beta + (beta - sin_beta) / (1 - cos(beta)) # noqa: E222 E261 E501
trig_term_sky = sin_beta + (np.pi - beta - sin_beta) / (1 + np.cos(beta))
trig_term_gnd = sin_beta + (beta - sin_beta) / (1 - np.cos(beta)) # noqa: E222 E261 E501

iam_sky = 1 - exp(-(c1 + c2 * trig_term_sky) * trig_term_sky / a_r)
iam_gnd = 1 - exp(-(c1 + c2 * trig_term_gnd) * trig_term_gnd / a_r)
iam_sky = 1 - np.exp(-(c1 + c2 * trig_term_sky) * trig_term_sky / a_r)
iam_gnd = 1 - np.exp(-(c1 + c2 * trig_term_gnd) * trig_term_gnd / a_r)

if out_index is not None:
iam_sky = pd.Series(iam_sky, index=out_index, name='iam_sky')
Expand Down
17 changes: 11 additions & 6 deletions pvlib/iotools/epw.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,19 @@ def read_epw(filename, coerce_year=None):
'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 '
'Safari/537.36')})
response = urlopen(request)
csvdata = io.StringIO(response.read().decode(errors='ignore'))
with io.StringIO(response.read().decode(errors='ignore')) as csvdata:
try:
data, meta = parse_epw(csvdata, coerce_year)
except Exception as e:
print(e)
else:
# Assume it's accessible via the file system
csvdata = open(str(filename), 'r')
try:
data, meta = parse_epw(csvdata, coerce_year)
finally:
csvdata.close()
with open(str(filename), 'r') as csvdata:
try:
data, meta = parse_epw(csvdata, coerce_year)
except Exception as e:
print(e)
Copy link
Member

Choose a reason for hiding this comment

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

I think we definitely want to propagate any parsing errors instead of printing them and letting execution continue, so better to get rid of the try/excepts in these two blocks.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks @chrisorner for the contribution and closing a long-standing annoying issue, and also thanks @kanderso-nrel for quick and thoughtful review. I apologize for commenting after the fact. I agree with Kevin (altho he might not agree with me). In my opinion we should restrict using print() in pvlib, except perhaps in examples, b/c it blocks the main execution thread which reduces performance. An alternative is logging which has many useful features, executes in separate thread, and therefore, does not block the main Python thread. However, as a rule pvlib has avoided logging except during development. Hope this makes sense to folks. Just my thoughts/opinions, definitely do not speak for anyone other than myself.

Copy link
Member

Choose a reason for hiding this comment

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

@mikofski just to be sure, would you change anything about the state of this PR as it was merged? Note that this printing was removed in a later commit and didn't make it into the final squashed diff.

I definitely agree that print() inside pvlib itself is never (or at least very rarely) the best way to present information to the user.

Copy link
Member

Choose a reason for hiding this comment

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

Nope, no changes. I was very happy with this PR and the review. Thanks again! Just wanted to make sure it was in the record that I extremely discourage print(), and I consider logging a better alternative although to date, hasn't been used in pvlib much.


return data, meta


Expand Down
1 change: 0 additions & 1 deletion pvlib/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import os
import datetime
import warnings

import pandas as pd
import pytz
Expand Down
1 change: 0 additions & 1 deletion pvlib/temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,6 @@ def fuentes(poa_global, temp_air, wind_speed, noct_installed, module_height=5,

# iterate through timeseries inputs
sun0 = 0
tmod0 = 293.15

# n.b. the way Fuentes calculates the first timedelta makes it seem like
# the value doesn't matter -- rather than recreate it here, just assume
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python

import os
import sys

try:
from setuptools import setup, find_namespace_packages
Expand Down
0