Skip to content

Resolving AttributeError when using ModelChain with multiple Arrays #1938

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

Closed
wants to merge 16 commits into from
Closed

Resolving AttributeError when using ModelChain with multiple Arrays #1938

wants to merge 16 commits into from

Conversation

matsuobasho
Copy link
Contributor

  • Closes AttributeError when using ModelChain with multiple Arrays #1759
  • I am familiar with the contributing guidelines
  • Tests added
  • Updates entries in docs/sphinx/source/reference for API changes. -- Doesn't seem to be relevant for PVSystem
  • Adds description and name entries in the appropriate "what's new" file in docs/sphinx/source/whatsnew for all changes. Includes link to the GitHub Issue with :issue:`num` or this Pull Request with :pull:`num`. Includes contributor name and/or GitHub username (link with :ghuser:`user`).
  • New code is fully documented. Includes numpydoc compliant docstrings, examples, and comments where necessary.
  • Pull request is nearly complete and ready for detailed review.
  • Maintainer: Appropriate GitHub Labels (including remote-data) and Milestone are assigned to the Pull Request and linked Issue.

Copy link
Member

@cwhanse cwhanse left a comment

Choose a reason for hiding this comment

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

Formatting suggestions


Testing
~~~~~~~


Documentation
~~~~~~~~~~~~~

* Update all examples in :ref:`pvsystem` User's guide page that reference
`pvsystem` to adhere to new required argument.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
`pvsystem` to adhere to new required argument.
`pvsystem` to adhere to new required argument.

Comment on lines +15 to +18
error in `ModelChain` instantiation when the `temperature_model_parameters`
for a `PVSystem` have not been set. Update requires `PVSystem` or `Array`
to have `temperature_model_parameters` explicitly or implicitly by providing
`racking_model` and `module_type`.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
error in `ModelChain` instantiation when the `temperature_model_parameters`
for a `PVSystem` have not been set. Update requires `PVSystem` or `Array`
to have `temperature_model_parameters` explicitly or implicitly by providing
`racking_model` and `module_type`.
error in `ModelChain` instantiation when the `temperature_model_parameters`
for a `PVSystem` have not been set. Update requires `PVSystem` or `Array`
to have `temperature_model_parameters` explicitly or implicitly by providing
`racking_model` and `module_type`.

@@ -977,6 +984,18 @@ def __init__(self, mount,
else:
self.temperature_model_parameters = temperature_model_parameters

if self.temperature_model_parameters=={}:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if self.temperature_model_parameters=={}:
if self.temperature_model_parameters == {}:

@@ -977,6 +984,18 @@ def __init__(self, mount,
else:
self.temperature_model_parameters = temperature_model_parameters

if self.temperature_model_parameters=={}:
raise ValueError("The `temperature_model_parameters` is empty "
"after an attempt to infer it. "
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"after an attempt to infer it. "
"after an attempt to infer it. "

if self.temperature_model_parameters=={}:
raise ValueError("The `temperature_model_parameters` is empty "
"after an attempt to infer it. "
"Pass either `temperature_model_parameters` to "
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"Pass either `temperature_model_parameters` to "
"Pass either `temperature_model_parameters` to "

raise ValueError("The `temperature_model_parameters` is empty "
"after an attempt to infer it. "
"Pass either `temperature_model_parameters` to "
"`Array` or `PVSystem` (if not passing arrays), or "
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"`Array` or `PVSystem` (if not passing arrays), or "
"`Array` or `PVSystem` (if not passing arrays), or"

"after an attempt to infer it. "
"Pass either `temperature_model_parameters` to "
"`Array` or `PVSystem` (if not passing arrays), or "
"`racking_module` to the `Array` `mount` "
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"`racking_module` to the `Array` `mount` "
" `racking_module` to the `Array` `mount` "

"Pass either `temperature_model_parameters` to "
"`Array` or `PVSystem` (if not passing arrays), or "
"`racking_module` to the `Array` `mount` "
"object and `module_type` to `Array. For guidance "
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"object and `module_type` to `Array. For guidance "
"object and `module_type` to `Array. For guidance"

"`Array` or `PVSystem` (if not passing arrays), or "
"`racking_module` to the `Array` `mount` "
"object and `module_type` to `Array. For guidance "
"on allowed values to use for `racking_module` and "
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"on allowed values to use for `racking_module` and "
" on values allowed for `racking_module` and "

mount = pvsystem.FixedMount(surface_tilt=20, surface_azimuth=180,
racking_model=racking_model)
with pytest.raises(ValueError, match='`temperature_model_parameters` is empty'):
pvsystem.Array(mount = mount, module_type=module_type)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
pvsystem.Array(mount = mount, module_type=module_type)
pvsystem.Array(mount=mount, module_type=module_type)

@matsuobasho
Copy link
Contributor Author

@cwhanse, these all look like formatting changes that I can accept right here. However, would like to understand the reason for these updates. For example:

image

Why do we need the line to begin with a space?

Is there a setting that I need to tweak in my linter / yapf to format it according to this standard? The only reference to spaces I see in the Contributing page is

Set your editor to strip extra whitespace from line endings. This prevents the git commit history from becoming cluttered with whitespace changes.

Thanks

@matsuobasho
Copy link
Contributor Author

I noticed that the Contributing document has 2 instances of PVSystem instantiation, which are just defined but not executed, so no error would come up during the build. Added the new required temperature_model_parameters argument in the 2 places of instantiation.

@cwhanse
Copy link
Member

cwhanse commented Jan 4, 2024

Why do we need the line to begin with a space?

It may be unnecessary but it makes the text file easier to read.

@cwhanse
Copy link
Member

cwhanse commented Jan 4, 2024

@pvlib/pvlib-maintainer this PR will change default behavior, although the current behavior is buggy. It will be required to provide either temperature_model_parameters, or a proper combination of racking_model and module_type. In the current behavior, a PVSystem can be instantiated without these inputs. In this PR, a ValueError would be raised.

What do we think about deprecation for this change? I view the change as primarily correcting a bug in v0.9.0 where we dropped defaulting to a SAPM temperature model when the inputs weren't supplied.

@kandersolar
Copy link
Member

Why do we need the line to begin with a space?

It may be unnecessary but it makes the text file easier to read.

Those RST files are used to build our documentation, and the spaces are necessary for that multi-line text to be considered a single bullet item instead of a bullet followed by a new paragraph. That file isn't included in our docs build yet, but you can check that currently it is not rendering correctly using GitHub's viewer: https://github.com/matsuobasho/pvlib-python/blob/main/docs/sphinx/source/whatsnew/v0.10.4.rst

In the current behavior, a PVSystem can be instantiated without these inputs. In this PR, a ValueError would be raised.

I still need to read and digest the discussion in #1759, but on the face of it, this seems not ideal to me. Currently it's possible to instantiate a PVSystem with no arguments at all. Seems strange to me for these temperature model inputs to be the only required inputs.

@matsuobasho
Copy link
Contributor Author

@cwhanse please confirm my interpretation that it's best to wait without making any updates to this until further word

@cwhanse
Copy link
Member

cwhanse commented Jan 5, 2024

@matsuobasho yes, we're sorting out what the desired behavior should be.

@@ -977,6 +984,18 @@ def __init__(self, mount,
else:
self.temperature_model_parameters = temperature_model_parameters

if self.temperature_model_parameters=={}:
Copy link
Member

Choose a reason for hiding this comment

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

@matsuobasho I agree with @kandersolar point of view, that we should remove this ValueError. I think we'll want to undo most of the changes in test_pvsystem.py as well. Because I can push to your fork, let me know if you'd like some help. And thanks again for your effort here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It'll be most efficient to delete this entire MR because there are so many changes that will not be used. The proposed change is just deleting two lines and will be easiest to recreate with a new MR.

Let me know if you can kill the entire MR. I'll then create a new MR with just that one change.

In this case, it looks like we do not need a new test or any docstring modifications?

Copy link
Member

Choose a reason for hiding this comment

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

You can close this PR and start a new one.

For the new PR I recommend that you first create a branch in your fork and use that branch for changes. Its not usually a good idea to make changes in your main branch.

First reset your main branch

git reset --hard upstream/ main where upstream is your name for pvlib/pvlib-python

Then create a branch

git checkout -b

Make the edits in the branch, add, commit, push, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AttributeError when using ModelChain with multiple Arrays
3 participants