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

Fix spurious test error with pandas 2.1 #1891

Merged
merged 1 commit into from
Oct 17, 2023
Merged

Conversation

kandersolar
Copy link
Member

@kandersolar kandersolar commented Oct 17, 2023

  • Closes #xxxx
  • I am familiar with the contributing guidelines
  • Tests added
  • Updates entries in docs/sphinx/source/reference 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 (including remote-data) and Milestone are assigned to the Pull Request and linked Issue.

As mentioned in #1827 (comment), a pyephem test is failing due to a units difference in pandas datetimes (example failure):

___________________ test_sun_rise_set_transit_ephem_horizon ____________________

golden = Location: 
  name: None
  latitude: 39.742476
  longitude: -105.1786
  altitude: 1830.14
  tz: America/Denver

    @requires_ephem
    def test_sun_rise_set_transit_ephem_horizon(golden):
        times = pd.DatetimeIndex([datetime.datetime(2016, 1, 3, 0, 0, 0)
                                  ]).tz_localize('MST')
        # center of sun disk
        center = solarposition.sun_rise_set_transit_ephem(
            times,
            latitude=golden.latitude, longitude=golden.longitude)
        edge = solarposition.sun_rise_set_transit_ephem(
            times,
            latitude=golden.latitude, longitude=golden.longitude, horizon='-0:34')
        result_rounded = (edge['sunrise'] - center['sunrise']).dt.round('min')
    
        sunrise_delta = datetime.datetime(2016, 1, 3, 7, 17, 11) - \
            datetime.datetime(2016, 1, 3, 7, 21, 33)
        expected = pd.Series(index=times,
                             data=sunrise_delta,
                             name='sunrise').dt.round('min')
>       assert_series_equal(expected, result_rounded)

pvlib/tests/test_solarposition.py:315: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

left = 2016-01-03 00:00:00-07:00   -1 days +23:56:00
Name: sunrise, dtype: timedelta64[us]
right = 2016-01-03 00:00:00-07:00   -1 days +23:56:00
Name: sunrise, dtype: timedelta64[ns]
kwargs = {'atol': 1e-05, 'rtol': 1e-05}

    def assert_series_equal(left, right, **kwargs):
        kwargs = _check_pandas_assert_kwargs(kwargs)
>       pd.testing.assert_series_equal(left, right, **kwargs)
E       AssertionError: Attributes of Series are different
E       
E       Attribute "dtype" are different
E       [left]:  timedelta64[us]
E       [right]: timedelta64[ns]

I think this pandas issue describes the problem: pandas-dev/pandas#55014

In short, the way we construct the expected value in the test results in different units for different pandas versions, and that causes the test to fail. What I don't understand is why it only affects the conda CI jobs. ah of course, it's because pyephem is optional and not installed in the "bare" jobs.

Anyway I hope this change gets the tests passing again.

@kandersolar kandersolar marked this pull request as ready for review October 17, 2023 19:25
@kandersolar kandersolar added this to the v0.10.3 milestone Oct 17, 2023
@kandersolar kandersolar merged commit 49be5b5 into pvlib:main Oct 17, 2023
30 checks passed
@kandersolar kandersolar deleted the testfix branch October 17, 2023 20:20
kandersolar added a commit that referenced this pull request Nov 29, 2023
* Remove various repeated words in documentation (#1872)

* Remove repeated words

* Update pvlib/ivtools/sdm.py

Co-authored-by: Kevin Anderson <kevin.anderso@gmail.com>

---------

Co-authored-by: Kevin Anderson <kevin.anderso@gmail.com>

* fix invalid escape sequence '\c' (#1879)

* fix invalid escape sequence '\c'

pvlib/iam.py:843: DeprecationWarning: invalid escape sequence '\c'

Occurence is actually in line 854: `IAM = 1 - (1 - \cos(aoi))^5`

* Add to list of contributors

* Replace use of deprecated `pkg_resources` (#1881) (#1882)

* Update infinite_sheds.py to add shaded fraction to returned variables in infinite_sheds.get_irradiance and infinite_sheds.get_irradiance_poa (#1871)

* Update infinite_sheds.py

Added shaded fraction to returned variables.

* Update v0.10.3.rst

* Update test_infinite_sheds.py

added tests for shaded fraction

* Update test_infinite_sheds.py

Corrected the shaded fraction tests in the haydavies portion.

* Update pvlib/bifacial/infinite_sheds.py

Co-authored-by: Kevin Anderson <kevin.anderso@gmail.com>

* Update infinite_sheds.py

* Update infinite_sheds.py

* Update infinite_sheds.py

fixed indentation issues

---------

Co-authored-by: Kevin Anderson <kevin.anderso@gmail.com>

* Continuous version of the Perez transposition model implementation (#1876)

* Definitely not ready for review!

* Big step forward.

* Add entry in docs.

* A working model but just one test sofar.

* Add new model as option in get_sky_diffuse.  Docstring edits pending.

* Completed doc strings.  Also a bit of fine-tuning code.

* Updated whatsnew.

* Bugfix, formatting fix, and add all tests.

* Test warning plus some other small changes.

* Make flake happy.

* Update pvlib/irradiance.py

Co-authored-by: Cliff Hansen <cwhanse@sandia.gov>

* Address comments.

* Add contributor code comments.

* Update pvlib/irradiance.py

Co-authored-by: Adam R. Jensen <39184289+AdamRJensen@users.noreply.github.com>

* Adapt to reviewer preferences.

* Adapt to flake preferences.

* Remove model pseudo-option.

* Flake

---------

Co-authored-by: Cliff Hansen <cwhanse@sandia.gov>
Co-authored-by: Adam R. Jensen <39184289+AdamRJensen@users.noreply.github.com>

* Fix spurious test error with pandas 2.1 (#1891)

pandas-dev/pandas#55014

* Fix plotting in plot_singlediode.py gallery page (#1895)

* Update plot_singlediode.py

fixed plot annotations by moving plt.show() further down

* Update whatsnew.rst

* Update v0.10.3.rst

* Update docs/sphinx/source/whatsnew.rst

Undoing changes to whatsnew.rst

* Address pandas FutureWarnings in test suite (#1900)

* Cahnged expected reference in test_detect_clearskY_window to 1 from True to avoid Futurewarning

* Change reference to etr in ibird function to avoid FutureWarning

* In test_modelchain, update all instances when referring to series by position to using iloc to get rid of FutureWarning

* Update to iloc method for referencing by position in test_irradiance to get rid of FutureWarning

* In test_singlediode change applymap to map to get rid of FutureWarning

* Test_srml update to select using iloc to get rid of FutureWarning

* Substitute changing to float64 dtype using map with base functionality that's accessible across Pandas versions

* Added username to Contributors

* Update line break in test_clearsky to adhere to line length limit

* add comparisons to other tools

* Apply suggestions from code review

Co-authored-by: Cliff Hansen <cwhanse@sandia.gov>

* revision re: other open-source projects

* bibtex tweaks

* clarify pvlib matlab comparison

---------

Co-authored-by: Miroslav Šedivý <6774676+eumiro@users.noreply.github.com>
Co-authored-by: Arjan Keeman <akeeman@users.noreply.github.com>
Co-authored-by: Miguel Sánchez de León Peque <peque@neosit.es>
Co-authored-by: Will Hobbs <45701090+williamhobbs@users.noreply.github.com>
Co-authored-by: Anton Driesse <anton.driesse@pvperformancelabs.com>
Co-authored-by: Cliff Hansen <cwhanse@sandia.gov>
Co-authored-by: Adam R. Jensen <39184289+AdamRJensen@users.noreply.github.com>
Co-authored-by: matsuobasho <rkoulikov@pm.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants