Skip to content
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

Add map_variables and -99999 nan value to read_crn #1368

Merged
merged 21 commits into from
Feb 17, 2022

Conversation

AdamRJensen
Copy link
Member

@AdamRJensen AdamRJensen commented Jan 5, 2022

  • Closes read_crn returns -99999 instead of NaN #1372
  • I am familiar with the contributing guidelines
  • Tests added
  • [ ] Updates entries to docs/sphinx/source/api.rst for API changes.
  • 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 and Milestone are assigned to the Pull Request and linked Issue.

I propose adding an argument map_variables to the read_crn function, which is the standard pattern for the iotools. Also, -99999 has been added to the list of nan values as per issue #1372.

Copy link
Member

@mikofski mikofski left a comment

Choose a reason for hiding this comment

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

LGTM

@kandersolar kandersolar added this to the 0.9.1 milestone Jan 6, 2022
Copy link
Member

@kandersolar kandersolar left a comment

Choose a reason for hiding this comment

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

Nice that this isn't a breaking change. Still needs a whatsnew entry though

pvlib/tests/iotools/test_crn.py Outdated Show resolved Hide resolved
AdamRJensen and others added 3 commits January 7, 2022 14:19
Co-authored-by: Kevin Anderson <57452607+kanderso-nrel@users.noreply.github.com>
Copy link
Member

@wholmgren wholmgren left a comment

Choose a reason for hiding this comment

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

Thanks @AdamRJensen! A couple of minor things below. Can you also update the PR title?

docs/sphinx/source/whatsnew/v0.9.1.rst Outdated Show resolved Hide resolved
pvlib/iotools/crn.py Outdated Show resolved Hide resolved
Comment on lines -106 to -110
try:
# to_datetime(utc=True) does not work in older versions of pandas
data = data.tz_localize('UTC')
except TypeError:
pass
Copy link
Member

Choose a reason for hiding this comment

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

Too bad I neglected to indicate the versions that needed this. I think the tests are comprehensive enough that we can safely remove this if they still pass.

pvlib/tests/iotools/test_crn.py Show resolved Hide resolved
pvlib/iotools/crn.py Outdated Show resolved Hide resolved
@AdamRJensen AdamRJensen changed the title Add map_variables to iotools.read_crn Add map_variables and -99999 nan value to read_crn Jan 10, 2022
@@ -12,7 +12,7 @@
'SOIL_MOISTURE_5 SOIL_TEMPERATURE_5 WETNESS WET_FLAG WIND_1_5 WIND_FLAG'
)

VARIABLE_MAP = {
CRN_VARIABLE_MAP = {
Copy link
Member

Choose a reason for hiding this comment

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

surfrad.py has VARIABLE_MAP while midc.py has MIDC_VARIABLE_MAP, so either the original or the change is consistent with existing code. I prefer just VARIABLE_MAP since it's simple and already specific to the module. Open to other ideas.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, I can get behind consistently using VARIABLE_MAP - though I have to admit that I might have done a similar change in previous PRs.

pvlib/tests/iotools/test_crn.py Show resolved Hide resolved
Comment on lines +114 to +115
# set dtypes here because dtype kwarg not supported in read_fwf until 0.20
data = data.astype(dict(zip(HEADERS, DTYPES)))
Copy link
Member

Choose a reason for hiding this comment

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

pvlib now requires pandas > 0.22 so perhaps we can remove this line in favor of the dtype kwarg

Copy link
Member Author

Choose a reason for hiding this comment

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

I do not believe this is possible as there are rows with all nans - and you cannot set the column dtype to int if the column contains nans. In the current version, the dtypes are set after the all nan rows are removed.

I get the following error when i set dtype=dict(zip(HEADERS, DTYPES)) with read_fwf:

ValueError: Unable to convert column WBANNO to type int64

pvlib/tests/iotools/test_crn.py Show resolved Hide resolved
@kandersolar kandersolar mentioned this pull request Jan 16, 2022
6 tasks
@wholmgren
Copy link
Member

Objections to merging this once the conflict is resolved? I think it's time for a 0.9.1.

@cwhanse
Copy link
Member

cwhanse commented Feb 16, 2022

Objections to merging this once the conflict is resolved? I think it's time for a 0.9.1.

No objection. Definitely time for 0.9.1

@kandersolar kandersolar merged commit c0c46b4 into pvlib:master Feb 17, 2022
@kandersolar
Copy link
Member

Thanks @AdamRJensen!

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

Successfully merging this pull request may close these issues.

read_crn returns -99999 instead of NaN
5 participants