From 1ac341b3ac877a39141975b799bd5e8fe8c9d499 Mon Sep 17 00:00:00 2001 From: DresdenGman Date: Fri, 20 Nov 2026 20:42:38 +0000 Subject: [PATCH 1/2] Simplify assert_*_equal wrappers in tests/conftest.py (#2263) Remove the assert_series_equal and assert_frame_equal wrappers around pandas.testing asserts and replace all call sites with direct pandas.testing calls carrying explicit tolerances. The wrappers silently rewrote caller tolerances (check_less_precise -> atol=rtol=1e-3, otherwise atol=rtol=1e-5, overriding any atol/rtol the caller passed) and carried dead pandas<1.1 version logic; the minimum supported pandas is 1.5.0. Simplify assert_index_equal to a thin compatibility shim that passes check_freq=False only on pandas >= 3.1.0, where the keyword exists; full removal of that wrapper must wait until pvlib requires pandas >= 3.1.0 (the CI minimum environment pins pandas 1.5.0). Add a regression test pinning the shim's version gate. Tests: 1135 passed (1133 affected-suite tests identical to the pre-change baseline plus 2 new shim tests), 35 skipped, 75 deselected (remote_data), 0 failed. flake8 --diff on the changed lines is clean. --- docs/sphinx/source/whatsnew/v0.16.2.rst | 7 + tests/bifacial/test_infinite_sheds.py | 24 +- tests/bifacial/test_pvfactors.py | 38 ++- tests/conftest.py | 38 +-- tests/iotools/test_acis.py | 18 +- tests/iotools/test_bsrn.py | 33 +- tests/iotools/test_crn.py | 11 +- tests/iotools/test_era5.py | 9 +- tests/iotools/test_nasa_power.py | 12 +- tests/iotools/test_psm4.py | 6 +- tests/iotools/test_pvgis.py | 15 +- tests/iotools/test_sodapro.py | 8 +- tests/iotools/test_solaranywhere.py | 6 +- tests/iotools/test_solargis.py | 9 +- tests/iotools/test_solrad.py | 18 +- tests/iotools/test_srml.py | 15 +- tests/iotools/test_surfrad.py | 6 +- tests/iotools/test_tmy.py | 3 +- tests/spectrum/test_irradiance.py | 16 +- tests/spectrum/test_mismatch.py | 4 +- tests/test_albedo.py | 5 +- tests/test_atmosphere.py | 8 +- tests/test_clearsky.py | 127 +++++--- tests/test_conftest.py | 63 ++-- tests/test_iam.py | 46 ++- tests/test_inverter.py | 53 +++- tests/test_irradiance.py | 165 +++++----- tests/test_location.py | 47 +-- tests/test_modelchain.py | 382 ++++++++++++++++++------ tests/test_pvarray.py | 3 +- tests/test_pvsystem.py | 244 ++++++++++----- tests/test_snow.py | 45 ++- tests/test_soiling.py | 13 +- tests/test_solarposition.py | 183 +++++++++--- tests/test_temperature.py | 65 ++-- tests/test_tracking.py | 60 ++-- 36 files changed, 1244 insertions(+), 561 deletions(-) diff --git a/docs/sphinx/source/whatsnew/v0.16.2.rst b/docs/sphinx/source/whatsnew/v0.16.2.rst index fb3ff54f76..cb0c764a59 100644 --- a/docs/sphinx/source/whatsnew/v0.16.2.rst +++ b/docs/sphinx/source/whatsnew/v0.16.2.rst @@ -56,6 +56,12 @@ Documentation Testing ~~~~~~~ +* Remove the ``assert_series_equal`` and ``assert_frame_equal`` wrappers + in ``tests/conftest.py`` and use ``pandas.testing`` functions directly, + with explicit tolerances at every call site. Simplify + ``assert_index_equal`` to a thin compatibility shim that passes + ``check_freq=False`` only on pandas >= 3.1.0, where the keyword exists. + (:issue:`2263`) Benchmarking @@ -84,3 +90,4 @@ Contributors * :ghuser:`xiajiahang` * Jakub Krasuski (:ghuser:`Blizzeq`) * Dylan Pulver (:ghuser:`dylanpulver`) +* Dresden Goehner (:ghuser:`DresdenGman`) diff --git a/tests/bifacial/test_infinite_sheds.py b/tests/bifacial/test_infinite_sheds.py index e9d45bcbf4..08f09294a3 100644 --- a/tests/bifacial/test_infinite_sheds.py +++ b/tests/bifacial/test_infinite_sheds.py @@ -5,7 +5,6 @@ import numpy as np import pandas as pd from pvlib.bifacial import infinite_sheds -from tests.conftest import assert_series_equal import pytest @@ -156,8 +155,16 @@ def test_get_irradiance_poa(): gcr, height, pitch, ghi, dhi, dni, albedo, iam=iam, npoints=npoints) assert isinstance(res, pd.DataFrame) - assert_series_equal(res['poa_global'], expected_global) - assert_series_equal(res['shaded_fraction'], expected_shaded_fraction) + pd.testing.assert_series_equal( + res['poa_global'], + expected_global, + atol=1e-5, + rtol=1e-5) + pd.testing.assert_series_equal( + res['shaded_fraction'], + expected_shaded_fraction, + atol=1e-5, + rtol=1e-5) assert all(k in res.columns for k in [ 'poa_global', 'poa_diffuse', 'poa_direct', 'poa_ground_diffuse', 'poa_sky_diffuse', 'shaded_fraction']) @@ -232,9 +239,14 @@ def test_get_irradiance(vectorize): expected_shaded_fraction = pd.Series( result_front['shaded_fraction'], index=ghi.index, name='shaded_fraction_front') - assert_series_equal(result['poa_global'], expected_poa_global) - assert_series_equal(result['shaded_fraction_front'], - expected_shaded_fraction) + pd.testing.assert_series_equal( + result['poa_global'], + expected_poa_global, + atol=1e-5, + rtol=1e-5) + pd.testing.assert_series_equal(result['shaded_fraction_front'], + expected_shaded_fraction, atol=1e-5, + rtol=1e-5) def test_get_irradiance_limiting_gcr(): diff --git a/tests/bifacial/test_pvfactors.py b/tests/bifacial/test_pvfactors.py index 26edcd1bb1..735458940e 100644 --- a/tests/bifacial/test_pvfactors.py +++ b/tests/bifacial/test_pvfactors.py @@ -1,7 +1,7 @@ import pandas as pd from datetime import datetime from pvlib.bifacial.pvfactors import pvfactors_timeseries -from tests.conftest import requires_pvfactors, assert_series_equal +from tests.conftest import requires_pvfactors import pytest @@ -47,8 +47,16 @@ def test_pvfactors_timeseries_list(example_values): """Test basic pvfactors functionality with list inputs""" inputs, outputs = example_values ipoa_inc_front, ipoa_inc_back, _, _ = pvfactors_timeseries(**inputs) - assert_series_equal(ipoa_inc_front, outputs['expected_ipoa_front']) - assert_series_equal(ipoa_inc_back, outputs['expected_ipoa_back']) + pd.testing.assert_series_equal( + ipoa_inc_front, + outputs['expected_ipoa_front'], + atol=1e-5, + rtol=1e-5) + pd.testing.assert_series_equal( + ipoa_inc_back, + outputs['expected_ipoa_back'], + atol=1e-5, + rtol=1e-5) @requires_pvfactors @@ -61,8 +69,16 @@ def test_pvfactors_timeseries_pandas(example_values): inputs[key] = pd.Series(inputs[key], index=inputs['timestamps']) ipoa_inc_front, ipoa_inc_back, _, _ = pvfactors_timeseries(**inputs) - assert_series_equal(ipoa_inc_front, outputs['expected_ipoa_front']) - assert_series_equal(ipoa_inc_back, outputs['expected_ipoa_back']) + pd.testing.assert_series_equal( + ipoa_inc_front, + outputs['expected_ipoa_front'], + atol=1e-5, + rtol=1e-5) + pd.testing.assert_series_equal( + ipoa_inc_back, + outputs['expected_ipoa_back'], + atol=1e-5, + rtol=1e-5) @requires_pvfactors @@ -78,5 +94,13 @@ def test_pvfactors_scalar_orientation(example_values): outputs['expected_ipoa_back'].iloc[1] = 81.72135884745822 ipoa_inc_front, ipoa_inc_back, _, _ = pvfactors_timeseries(**inputs) - assert_series_equal(ipoa_inc_front, outputs['expected_ipoa_front']) - assert_series_equal(ipoa_inc_back, outputs['expected_ipoa_back']) + pd.testing.assert_series_equal( + ipoa_inc_front, + outputs['expected_ipoa_front'], + atol=1e-5, + rtol=1e-5) + pd.testing.assert_series_equal( + ipoa_inc_back, + outputs['expected_ipoa_back'], + atol=1e-5, + rtol=1e-5) diff --git a/tests/conftest.py b/tests/conftest.py index 19a44de38f..c7634e6111 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -38,41 +38,17 @@ def inner(*args, **kwargs): return wrapper -def _check_pandas_assert_kwargs(kwargs): - # handles the change in API related to default - # tolerances in pandas 1.1.0. See pvlib GH #1018 - if Version(pd.__version__) >= Version('1.1.0'): - if kwargs.pop('check_less_precise', False): - kwargs['atol'] = 1e-3 - kwargs['rtol'] = 1e-3 - else: - kwargs['atol'] = 1e-5 - kwargs['rtol'] = 1e-5 - else: - kwargs.pop('rtol', None) - kwargs.pop('atol', None) - return kwargs - - def assert_index_equal(left, right, **kwargs): - kwargs = _check_pandas_assert_kwargs(kwargs) - if Version(pd.__version__) >= Version('3.1.0'): - # check_freq was added in pandas 3.1.0 - # tests written prior to it, may have not taken it into account - kwargs['check_freq'] = False + # check_freq was added to pandas.testing.assert_index_equal in pandas + # 3.1.0; on older pandas the kwarg does not exist. Only pass it where + # the installed pandas supports it. This wrapper can be removed (and + # call sites switched to pd.testing.assert_index_equal) once pvlib + # requires pandas >= 3.1.0. See #2263 and #2924. + if Version(pd.__version__) >= Version("3.1.0"): + kwargs["check_freq"] = False pd.testing.assert_index_equal(left, right, **kwargs) -def assert_series_equal(left, right, **kwargs): - kwargs = _check_pandas_assert_kwargs(kwargs) - pd.testing.assert_series_equal(left, right, **kwargs) - - -def assert_frame_equal(left, right, **kwargs): - kwargs = _check_pandas_assert_kwargs(kwargs) - pd.testing.assert_frame_equal(left, right, **kwargs) - - # commonly used directories in the tests TEST_DIR = Path(__file__).parent PVLIB_DATA_DIR = Path(pvlib.__path__[0]) / 'data' diff --git a/tests/iotools/test_acis.py b/tests/iotools/test_acis.py index 7db591f749..00098d13bc 100644 --- a/tests/iotools/test_acis.py +++ b/tests/iotools/test_acis.py @@ -9,7 +9,7 @@ get_acis_prism, get_acis_nrcc, get_acis_mpe, get_acis_station_data, get_acis_available_stations ) -from tests.conftest import RERUNS, RERUNS_DELAY, assert_frame_equal +from tests.conftest import RERUNS, RERUNS_DELAY from requests import HTTPError @@ -28,7 +28,7 @@ def test_get_acis_prism(): 'heating_degree_days', 'growing_degree_days'], index=pd.to_datetime(['2020-01-01', '2020-01-02']), ) - assert_frame_equal(df, expected) + pd.testing.assert_frame_equal(df, expected, atol=1e-5, rtol=1e-5) expected_meta = {'latitude': 40, 'longitude': -80, 'altitude': 298.0944} assert meta == expected_meta @@ -36,7 +36,7 @@ def test_get_acis_prism(): df, meta = get_acis_prism(40.001, -80.001, '2020-01-01', '2020-01-02', map_variables=False) expected.columns = ['pcpn', 'maxt', 'mint', 'avgt', 'cdd', 'hdd', 'gdd'] - assert_frame_equal(df, expected) + pd.testing.assert_frame_equal(df, expected, atol=1e-5, rtol=1e-5) expected_meta = {'lat': 40, 'lon': -80, 'elev': 298.0944} assert meta == expected_meta @@ -57,7 +57,7 @@ def test_get_acis_nrcc(grid, expected): 'heating_degree_days', 'growing_degree_days'], index=pd.to_datetime(['2020-01-01']), ) - assert_frame_equal(df, expected) + pd.testing.assert_frame_equal(df, expected, atol=1e-5, rtol=1e-5) expected_meta = {'latitude': 40., 'longitude': -80., 'altitude': 356.9208} assert meta == pytest.approx(expected_meta) @@ -65,7 +65,7 @@ def test_get_acis_nrcc(grid, expected): df, meta = get_acis_nrcc(40.001, -80.001, '2020-01-01', '2020-01-01', grid, map_variables=False) expected.columns = ['pcpn', 'maxt', 'mint', 'avgt', 'cdd', 'hdd', 'gdd'] - assert_frame_equal(df, expected) + pd.testing.assert_frame_equal(df, expected, atol=1e-5, rtol=1e-5) expected_meta = {'lat': 40., 'lon': -80., 'elev': 356.9208} assert meta == pytest.approx(expected_meta) @@ -87,7 +87,7 @@ def test_get_acis_mpe(): {'precipitation': [0.4, 0.0]}, index=pd.to_datetime(['2020-01-01', '2020-01-02']), ) - assert_frame_equal(df, expected) + pd.testing.assert_frame_equal(df, expected, atol=1e-5, rtol=1e-5) expected_meta = {'latitude': 40.0083, 'longitude': -79.9653} assert meta == expected_meta @@ -95,7 +95,7 @@ def test_get_acis_mpe(): df, meta = get_acis_mpe(40.001, -80.001, '2020-01-01', '2020-01-02', map_variables=False) expected.columns = ['pcpn'] - assert_frame_equal(df, expected) + pd.testing.assert_frame_equal(df, expected, atol=1e-5, rtol=1e-5) expected_meta = {'lat': 40.0083, 'lon': -79.9653} assert meta == expected_meta @@ -116,7 +116,7 @@ def test_get_acis_station_data(): 'heating_degree_days', 'growing_degree_days'], index=pd.to_datetime(['2020-01-10', '2020-01-11', '2020-01-12']), ) - assert_frame_equal(df, expected) + pd.testing.assert_frame_equal(df, expected, atol=1e-5, rtol=1e-5) expected_meta = { 'uid': 48, 'state': 'IL', @@ -177,7 +177,7 @@ def test_get_acis_station_data(): trace_val=-99, map_variables=False) expected.columns = ['maxt', 'mint', 'avgt', 'obst', 'pcpn', 'snow', 'snwd', 'cdd', 'hdd', 'gdd'] - assert_frame_equal(df, expected) + pd.testing.assert_frame_equal(df, expected, atol=1e-5, rtol=1e-5) expected_meta['lat'] = expected_meta.pop('latitude') expected_meta['lon'] = expected_meta.pop('longitude') expected_meta['elev'] = expected_meta.pop('altitude') diff --git a/tests/iotools/test_bsrn.py b/tests/iotools/test_bsrn.py index 6b5f356836..3104fffddb 100644 --- a/tests/iotools/test_bsrn.py +++ b/tests/iotools/test_bsrn.py @@ -12,8 +12,7 @@ RERUNS, RERUNS_DELAY, assert_index_equal, - requires_bsrn_credentials, -) + requires_bsrn_credentials) @pytest.fixture(scope="module") @@ -39,7 +38,11 @@ def expected_index(): ]) def test_read_bsrn(testfile, expected_index): data, metadata = read_bsrn(TESTS_DATA_DIR / testfile) - assert_index_equal(expected_index, data.index) + assert_index_equal( + expected_index, + data.index, + atol=1e-5, + rtol=1e-5) assert 'ghi' in data.columns assert 'dni_std' in data.columns assert 'dhi_min' in data.columns @@ -50,7 +53,11 @@ def test_read_bsrn(testfile, expected_index): def test_read_bsrn_buffer(expected_index): with open(TESTS_DATA_DIR / 'bsrn-lr0100-pay0616.dat') as fbuf: data, metadata = read_bsrn(fbuf) - assert_index_equal(expected_index, data.index) + assert_index_equal( + expected_index, + data.index, + atol=1e-5, + rtol=1e-5) assert 'ghi' in data.columns assert 'dni_std' in data.columns assert 'dhi_min' in data.columns @@ -63,7 +70,11 @@ def test_read_bsrn_logical_records(expected_index): # and that 0100 is not passed when not specified data, metadata = read_bsrn(TESTS_DATA_DIR / 'bsrn-pay0616.dat.gz', logical_records=['0300', '0500']) - assert_index_equal(expected_index, data.index) + assert_index_equal( + expected_index, + data.index, + atol=1e-5, + rtol=1e-5) assert 'lwu' in data.columns assert 'uva_global' in data.columns assert 'uvb_reflected_std' in data.columns @@ -107,7 +118,11 @@ def test_get_bsrn(expected_index, bsrn_credentials): username=username, password=password, save_path=temp_dir.name) - assert_index_equal(expected_index, data.index) + assert_index_equal( + expected_index, + data.index, + atol=1e-5, + rtol=1e-5) assert 'ghi' in data.columns assert 'dni_std' in data.columns assert 'dhi_min' in data.columns @@ -115,7 +130,11 @@ def test_get_bsrn(expected_index, bsrn_credentials): assert 'relative_humidity' in data.columns # test that a local file was saved and is read correctly data2, metadata2 = read_bsrn(os.path.join(temp_dir.name, 'tam0616.dat.gz')) - assert_index_equal(expected_index, data2.index) + assert_index_equal( + expected_index, + data2.index, + atol=1e-5, + rtol=1e-5) assert 'ghi' in data2.columns temp_dir.cleanup() # explicitly remove temporary directory diff --git a/tests/iotools/test_crn.py b/tests/iotools/test_crn.py index 55c9d6440e..389765bab0 100644 --- a/tests/iotools/test_crn.py +++ b/tests/iotools/test_crn.py @@ -5,7 +5,6 @@ from pvlib.iotools import crn from tests.conftest import ( TESTS_DATA_DIR, - assert_frame_equal, assert_index_equal, ) @@ -77,13 +76,17 @@ def test_read_crn(testfile, columns_mapped, dtypes): expected[col] = expected[col].astype(_dtype) out = crn.read_crn(testfile) - assert_frame_equal(out, expected) + pd.testing.assert_frame_equal(out, expected, atol=1e-5, rtol=1e-5) # Test map_variables=False returns correct column names def test_read_crn_map_variables(testfile, columns_unmapped, dtypes): out = crn.read_crn(testfile, map_variables=False) - assert_index_equal(out.columns, pd.Index(columns_unmapped)) + assert_index_equal( + out.columns, + pd.Index(columns_unmapped), + atol=1e-5, + rtol=1e-5) def test_read_crn_problems(testfile_problems, columns_mapped, dtypes): @@ -103,4 +106,4 @@ def test_read_crn_problems(testfile_problems, columns_mapped, dtypes): if _dtype is not None: expected[col] = expected[col].astype(_dtype) out = crn.read_crn(testfile_problems) - assert_frame_equal(out, expected) + pd.testing.assert_frame_equal(out, expected, atol=1e-5, rtol=1e-5) diff --git a/tests/iotools/test_era5.py b/tests/iotools/test_era5.py index 3afab97ffd..3a93c5c4eb 100644 --- a/tests/iotools/test_era5.py +++ b/tests/iotools/test_era5.py @@ -12,8 +12,7 @@ RERUNS, RERUNS_DELAY, assert_index_equal, - requires_ecmwf_credentials, -) + requires_ecmwf_credentials) @pytest.fixture @@ -71,7 +70,11 @@ def test_get_era5_land(params, expected): df, meta = pvlib.iotools.get_era5(**params) assert np.isclose(meta['longitude'], -80.0) assert np.isclose(meta['latitude'], 40.0) - assert_index_equal(df.index, expected.index) + assert_index_equal( + df.index, + expected.index, + atol=1e-5, + rtol=1e-5) assert set(df.columns) == {'ghi', 'temp_air'} assert df.notna().all().all() diff --git a/tests/iotools/test_nasa_power.py b/tests/iotools/test_nasa_power.py index 7d7ffeab32..61156ea512 100644 --- a/tests/iotools/test_nasa_power.py +++ b/tests/iotools/test_nasa_power.py @@ -39,7 +39,11 @@ def test_get_nasa_power(data_index, ghi_series): assert meta['time_standard'] == 'UTC' assert meta['title'] == 'NASA/POWER Source Native Resolution Hourly Data' # Assert that the index is parsed correctly - assert_index_equal(data.index, data_index) + assert_index_equal( + data.index, + data_index, + atol=1e-5, + rtol=1e-5) # Test one column pd.testing.assert_series_equal(data['ALLSKY_SFC_SW_DWN'], ghi_series, check_freq=False, check_names=False) @@ -54,7 +58,11 @@ def test_get_nasa_power_pvlib_params_naming(data_index, ghi_series): end=data_index[-1], parameters=['ghi']) # Assert that the index is parsed correctly - assert_index_equal(data.index, data_index) + assert_index_equal( + data.index, + data_index, + atol=1e-5, + rtol=1e-5) # Test one column pd.testing.assert_series_equal(data['ghi'], ghi_series, check_freq=False) diff --git a/tests/iotools/test_psm4.py b/tests/iotools/test_psm4.py index 51d06dbf9d..88d8c7eca0 100644 --- a/tests/iotools/test_psm4.py +++ b/tests/iotools/test_psm4.py @@ -252,7 +252,11 @@ def test_read_nsrdb_psm4_map_variables(): 'relative_humidity', 'solar_zenith', 'SSA', 'albedo', 'pressure', 'precipitable_water', 'wind_direction', 'wind_speed'] - assert_index_equal(data.columns, pd.Index(columns_mapped)) + assert_index_equal( + data.columns, + pd.Index(columns_mapped), + atol=1e-5, + rtol=1e-5) def test_read_nsrdb_psm4_quoted_columns_with_commas(): diff --git a/tests/iotools/test_pvgis.py b/tests/iotools/test_pvgis.py index 32d820faae..4941a724c4 100644 --- a/tests/iotools/test_pvgis.py +++ b/tests/iotools/test_pvgis.py @@ -13,10 +13,7 @@ from tests.conftest import ( TESTS_DATA_DIR, RERUNS, - RERUNS_DELAY, - assert_frame_equal, - assert_series_equal, -) + RERUNS_DELAY) # PVGIS Hourly tests @@ -202,7 +199,7 @@ def test_read_pvgis_hourly(testfile, expected_name, metadata_exp, out, metadata = read_pvgis_hourly( testfile, map_variables=map_variables, pvgis_format=pvgis_format) # Assert whether dataframe, metadata, and inputs are as expected - assert_frame_equal(out, expected) + pd.testing.assert_frame_equal(out, expected, atol=1e-5, rtol=1e-5) assert metadata == metadata_exp @@ -262,7 +259,7 @@ def test_get_pvgis_hourly(requests_mock, testfile, expected_name, args, # Get expected dataframe from fixture expected = request.getfixturevalue(expected_name) # Compare out and expected dataframes - assert_frame_equal(out, expected) + pd.testing.assert_frame_equal(out, expected, atol=1e-5, rtol=1e-5) def test_get_pvgis_hourly_bad_status_code(requests_mock): @@ -585,7 +582,11 @@ def test_read_pvgis_horizon(): horizon_data = pd.read_csv(TESTS_DATA_DIR / 'test_read_pvgis_horizon.csv', index_col=0) horizon_data = horizon_data['horizon_elevation'] - assert_series_equal(pvgis_data, horizon_data) + pd.testing.assert_series_equal( + pvgis_data, + horizon_data, + atol=1e-5, + rtol=1e-5) @pytest.mark.remote_data diff --git a/tests/iotools/test_sodapro.py b/tests/iotools/test_sodapro.py index cf40c654a2..1b38e46ba7 100644 --- a/tests/iotools/test_sodapro.py +++ b/tests/iotools/test_sodapro.py @@ -8,7 +8,7 @@ import pytest from pvlib.iotools import sodapro -from tests.conftest import TESTS_DATA_DIR, assert_frame_equal +from tests.conftest import TESTS_DATA_DIR from pvlib._deprecation import pvlibDeprecationWarning @@ -177,7 +177,7 @@ def test_read_cams(testfile, index, columns, values, dtypes): expected = generate_expected_dataframe(values, columns, index, dtypes) out, metadata = sodapro.read_cams(testfile, integrated=False, map_variables=True) - assert_frame_equal(out, expected, check_less_precise=True) + pd.testing.assert_frame_equal(out, expected, atol=1e-3, rtol=1e-3) def test_read_cams_integrated_unmapped_label(): @@ -190,7 +190,7 @@ def test_read_cams_integrated_unmapped_label(): out, metadata = sodapro.read_cams(testfile_radiation_verbose, integrated=True, label='right', map_variables=False) - assert_frame_equal(out, expected, check_less_precise=True) + pd.testing.assert_frame_equal(out, expected, atol=1e-3, rtol=1e-3) def test_read_cams_metadata(): @@ -236,7 +236,7 @@ def test_get_cams(requests_mock, testfile, index, columns, values, dtypes, verbose=False, integrated=False) expected = generate_expected_dataframe(values, columns, index, dtypes) - assert_frame_equal(out, expected, check_less_precise=True) + pd.testing.assert_frame_equal(out, expected, atol=1e-3, rtol=1e-3) # Test if Warning is raised if verbose mode is True and time_step != '1min' with pytest.warns(UserWarning, match='Verbose mode only supports'): diff --git a/tests/iotools/test_solaranywhere.py b/tests/iotools/test_solaranywhere.py index 5f4dedfbe1..568a87d4bd 100644 --- a/tests/iotools/test_solaranywhere.py +++ b/tests/iotools/test_solaranywhere.py @@ -7,8 +7,7 @@ RERUNS, RERUNS_DELAY, assert_index_equal, - requires_solaranywhere_credentials, -) + requires_solaranywhere_credentials) # High spatial resolution and 5-min data, true dynamics enabled TESTFILE_HIGH_RESOLUTION = TESTS_DATA_DIR / 'Burlington, United States SolarAnywhere Time Series 20210101 to 20210103 Lat_44_4675 Lon_-73_2075 SA format.csv' # noqa: E501 @@ -75,9 +74,10 @@ def test_read_solaranywhere_high_resolution(high_resolution_index): assert data.loc['2021-01-01 07:00:00-05:00', 'Albedo'] == 0.6 assert data.loc['2021-01-01 07:00:00-05:00', 'WindSpeed (m/s)'] == 0 # Assert that the index is parsed correctly - assert_index_equal( # from conftest; doesn't compare index frequency attr + assert_index_equal( data.index, high_resolution_index, + atol=1e-5, rtol=1e-5, ) diff --git a/tests/iotools/test_solargis.py b/tests/iotools/test_solargis.py index eced226595..c622e0a091 100644 --- a/tests/iotools/test_solargis.py +++ b/tests/iotools/test_solargis.py @@ -5,7 +5,6 @@ from tests.conftest import ( RERUNS, RERUNS_DELAY, - assert_frame_equal, assert_index_equal, ) @@ -44,7 +43,7 @@ def test_get_solargis(hourly_dataframe): start='2022-01-01', end='2022-01-01', tz='GMT+01', variables=['GHI', 'DNI'], time_resolution='HOURLY', api_key='demo') - assert_frame_equal(data, hourly_dataframe) + pd.testing.assert_frame_equal(data, hourly_dataframe, atol=1e-5, rtol=1e-5) @pytest.mark.remote_data @@ -58,7 +57,11 @@ def test_get_solargis_utc_start_timestamp(hourly_index_start_utc): time_resolution='MIN_30', map_variables=False, api_key='demo') assert 'GTI' in data.columns # assert that variables aren't mapped - assert_index_equal(data.index, hourly_index_start_utc) + assert_index_equal( + data.index, + hourly_index_start_utc, + atol=1e-5, + rtol=1e-5) @pytest.mark.remote_data diff --git a/tests/iotools/test_solrad.py b/tests/iotools/test_solrad.py index 387ef026f2..0db3a6093c 100644 --- a/tests/iotools/test_solrad.py +++ b/tests/iotools/test_solrad.py @@ -7,10 +7,8 @@ from pvlib.iotools import solrad from tests.conftest import ( TESTS_DATA_DIR, - assert_frame_equal, RERUNS, - RERUNS_DELAY, -) + RERUNS_DELAY) testfile = TESTS_DATA_DIR / 'abq19056.dat' @@ -108,7 +106,7 @@ def test_read_solrad(testfile, index, columns, values, dtypes, meta): for (col, _dtype) in zip(expected.columns, dtypes): expected[col] = expected[col].astype(_dtype) out, m = solrad.read_solrad(testfile) - assert_frame_equal(out, expected) + pd.testing.assert_frame_equal(out, expected, atol=1e-5, rtol=1e-5) assert m == meta @@ -121,7 +119,11 @@ def test_read_solrad_https(): local_data, _ = solrad.read_solrad(testfile_mad) remote_data, _ = solrad.read_solrad(https_testfile) # local file only contains four rows to save space - assert_frame_equal(local_data, remote_data.iloc[:4]) + pd.testing.assert_frame_equal( + local_data, + remote_data.iloc[:4], + atol=1e-5, + rtol=1e-5) @pytest.mark.remote_data @@ -142,7 +144,11 @@ def test_get_solrad(testfile, station): expected, _ = solrad.read_solrad(testfile) actual = df.reindex(expected.index) # ABQ test file has an unexplained NaN in row 4; just verify first 3 rows - assert_frame_equal(actual.iloc[:3], expected.iloc[:3]) + pd.testing.assert_frame_equal( + actual.iloc[:3], + expected.iloc[:3], + atol=1e-5, + rtol=1e-5) @pytest.mark.remote_data diff --git a/tests/iotools/test_srml.py b/tests/iotools/test_srml.py index c40ea494c1..bb6a256a94 100644 --- a/tests/iotools/test_srml.py +++ b/tests/iotools/test_srml.py @@ -8,7 +8,6 @@ RERUNS, RERUNS_DELAY, assert_index_equal, - assert_frame_equal, ) srml_testfile = TESTS_DATA_DIR / 'SRML-day-EUPO1801.txt' @@ -89,7 +88,7 @@ def test_get_srml(): file_data = srml.read_srml(url) requested, _ = srml.get_srml(station='EU', start='2018-01-01', end='2018-01-31') - assert_frame_equal(file_data, requested) + pd.testing.assert_frame_equal(file_data, requested, atol=1e-5, rtol=1e-5) @pytest.mark.remote_data @@ -99,7 +98,11 @@ def test_get_srml_hourly(): end='1986-05-31', filetype='PH') expected_index = pd.date_range(start='1986-04-01', end='1986-05-31 23:59', freq='1h', tz='Etc/GMT+8') - assert_index_equal(data.index, expected_index) + assert_index_equal( + data.index, + expected_index, + atol=1e-5, + rtol=1e-5) @pytest.mark.remote_data @@ -110,7 +113,11 @@ def test_get_srml_minute(): end='2018-01-31', filetype='PO') expected_index = pd.date_range(start='2018-01-01', end='2018-01-31 23:59', freq='1min', tz='Etc/GMT+8') - assert_index_equal(data_get.index, expected_index) + assert_index_equal( + data_get.index, + expected_index, + atol=1e-5, + rtol=1e-5) assert all(c in data_get.columns for c in data_read.columns) # Check that all indices in example file are present in remote file assert data_read.index.isin(data_get.index).all() diff --git a/tests/iotools/test_surfrad.py b/tests/iotools/test_surfrad.py index f377a292af..94adb10129 100644 --- a/tests/iotools/test_surfrad.py +++ b/tests/iotools/test_surfrad.py @@ -4,10 +4,8 @@ from pvlib.iotools import surfrad from tests.conftest import ( TESTS_DATA_DIR, - assert_frame_equal, RERUNS, - RERUNS_DELAY, -) + RERUNS_DELAY) testfile = TESTS_DATA_DIR / 'surfrad-slv16001.dat' network_testfile = ('ftp://aftp.cmdl.noaa.gov/data/radiation/surfrad/' @@ -93,7 +91,7 @@ def test_get_surfrad(): assert df.index[-1] == pd.to_datetime('2016-01-01 23:59+00:00') expected, _ = surfrad.read_surfrad(testfile) - assert_frame_equal(df, expected) + pd.testing.assert_frame_equal(df, expected, atol=1e-5, rtol=1e-5) @pytest.mark.remote_data diff --git a/tests/iotools/test_tmy.py b/tests/iotools/test_tmy.py index c95f89986b..b0c97d6e64 100644 --- a/tests/iotools/test_tmy.py +++ b/tests/iotools/test_tmy.py @@ -111,9 +111,10 @@ def test_solaranywhere_tmy3(solaranywhere_index): # included to test files with 00:00 timestamps are parsed correctly data, meta = tmy.read_tmy3(TMY3_SOLARANYWHERE, encoding='iso-8859-1', map_variables=False) - assert_index_equal( # from conftest; doesn't compare index frequency attr + assert_index_equal( data.index, solaranywhere_index, + atol=1e-5, rtol=1e-5, ) assert meta['USAF'] == 0 assert meta['Name'] == 'Burlington United States' diff --git a/tests/spectrum/test_irradiance.py b/tests/spectrum/test_irradiance.py index 59ce66b269..d29b78a679 100644 --- a/tests/spectrum/test_irradiance.py +++ b/tests/spectrum/test_irradiance.py @@ -4,8 +4,6 @@ import numpy as np from pvlib import spectrum -from tests.conftest import assert_series_equal - def test_get_reference_spectra_am15g(): # test that the reference spectrum is read and interpolated correctly @@ -42,7 +40,11 @@ def test_get_reference_spectra(reference_identifier, expected_sums): assert standard.index.name == "wavelength" assert standard.index.is_monotonic_increasing is True expected_sums = pd.Series(expected_sums) # convert prior to comparison - assert_series_equal(np.sum(standard, axis=0), expected_sums, atol=1e-2) + pd.testing.assert_series_equal( + np.sum(standard, axis=0), + expected_sums, + atol=1e-5, + rtol=1e-5) def test_get_reference_spectra_custom_wavelengths(): @@ -59,7 +61,11 @@ def test_get_reference_spectra_custom_wavelengths(): assert_equal(len(standard), len(wavelength)) # check no NaN values were returned assert not standard.isna().any().any() # double any to return one value - assert_series_equal(np.sum(standard, axis=0), expected_sums, atol=1e-4) + pd.testing.assert_series_equal( + np.sum(standard, axis=0), + expected_sums, + atol=1e-5, + rtol=1e-5) def test_get_reference_spectra_invalid_reference(): @@ -87,7 +93,7 @@ def test_average_photon_energy_dataframe(): ape = spectrum.average_photon_energy(spectra) expected = pd.Series([1.36848, 1.45017, 1.40885]) expected.index = spectra.index - assert_series_equal(ape, expected, rtol=1e-4) + pd.testing.assert_series_equal(ape, expected, rtol=1e-5, atol=1e-5) def test_average_photon_energy_invalid_type(): diff --git a/tests/spectrum/test_mismatch.py b/tests/spectrum/test_mismatch.py index f0443d4ce7..780c7f3534 100644 --- a/tests/spectrum/test_mismatch.py +++ b/tests/spectrum/test_mismatch.py @@ -4,8 +4,6 @@ import numpy as np from pvlib import spectrum -from tests.conftest import assert_series_equal - def test_calc_spectral_mismatch_field(spectrl2_data): # test that the mismatch is calculated correctly with @@ -137,7 +135,7 @@ def test_spectral_factor_sapm(sapm_module_params, airmass, expected): out = spectrum.spectral_factor_sapm(airmass, sapm_module_params) if isinstance(airmass, pd.Series): - assert_series_equal(out, expected, check_less_precise=4) + pd.testing.assert_series_equal(out, expected, atol=1e-3, rtol=1e-3) else: assert_allclose(out, expected, atol=1e-4) diff --git a/tests/test_albedo.py b/tests/test_albedo.py index 5e4c35258a..b956015c39 100644 --- a/tests/test_albedo.py +++ b/tests/test_albedo.py @@ -3,7 +3,6 @@ import pytest from pvlib import albedo -from .conftest import assert_series_equal from numpy.testing import assert_allclose @@ -48,7 +47,7 @@ def test_inland_water_dvoracek_series(): color_coeff=color_coeffs, wave_roughness_coeff=roughness_coeffs) # noqa: E501 expected = pd.Series([0.1, 0.1, 0.12875, 0.06278, 0.064], index=times) - assert_series_equal(expected, result, atol=1e-5) + pd.testing.assert_series_equal(expected, result, atol=1e-5, rtol=1e-5) def test_inland_water_dvoracek_series_mix_with_array(): @@ -61,7 +60,7 @@ def test_inland_water_dvoracek_series_mix_with_array(): color_coeff=color_coeffs, wave_roughness_coeff=roughness_coeffs) # noqa: E501 expected = pd.Series([0.08555, 0.07787], index=times) - assert_series_equal(expected, result, atol=1e-5) + pd.testing.assert_series_equal(expected, result, atol=1e-5, rtol=1e-5) def test_inland_water_dvoracek_invalid(): diff --git a/tests/test_atmosphere.py b/tests/test_atmosphere.py index 6236fe5ab0..56a7542fa1 100644 --- a/tests/test_atmosphere.py +++ b/tests/test_atmosphere.py @@ -4,7 +4,6 @@ from numpy import nan from numpy.testing import assert_allclose import pandas as pd -from .conftest import assert_series_equal import pytest from pvlib import atmosphere @@ -47,7 +46,7 @@ def test_airmass(model, expected, zeniths): zeniths = pd.Series(zeniths, index=times) expected = pd.Series(expected, index=times) out = atmosphere.get_relative_airmass(zeniths, model) - assert_series_equal(out, expected, check_less_precise=True) + pd.testing.assert_series_equal(out, expected, atol=1e-3, rtol=1e-3) def test_airmass_scalar(): @@ -329,8 +328,9 @@ def test_windspeed_powerlaw_series(windspeeds_data_powerlaw): windspeeds_data_powerlaw["height_ref"], windspeeds_data_powerlaw["height_desired"], surface_type='unstable_air_above_open_water_surface') - assert_series_equal(windspeeds_data_powerlaw["wind_calc"], - result, check_names=False) + pd.testing.assert_series_equal(windspeeds_data_powerlaw["wind_calc"], + result, check_names=False, atol=1e-5, + rtol=1e-5) def test_windspeed_powerlaw_invalid(): diff --git a/tests/test_clearsky.py b/tests/test_clearsky.py index 20d88679ff..8949e8df8d 100644 --- a/tests/test_clearsky.py +++ b/tests/test_clearsky.py @@ -6,7 +6,6 @@ import pytest from numpy.testing import assert_allclose -from .conftest import assert_frame_equal, assert_series_equal from pvlib.location import Location from pvlib import clearsky @@ -42,7 +41,7 @@ def test_ineichen_series(): index=times) out = clearsky.ineichen(apparent_zenith, am, 3) - assert_frame_equal(expected, out) + pd.testing.assert_frame_equal(expected, out, atol=1e-5, rtol=1e-5) def test_ineichen_series_perez_enhancement(): @@ -70,7 +69,7 @@ def test_ineichen_series_perez_enhancement(): index=times) out = clearsky.ineichen(apparent_zenith, am, 3, perez_enhancement=True) - assert_frame_equal(expected, out) + pd.testing.assert_frame_equal(expected, out, atol=1e-5, rtol=1e-5) def test_ineichen_scalar_input(): @@ -175,7 +174,7 @@ def test_ineichen_dni_extra(): columns=['ghi', 'dni', 'dhi']) out = clearsky.ineichen(10, 1, 3, dni_extra=pd.Series(1370)) - assert_frame_equal(expected, out) + pd.testing.assert_frame_equal(expected, out, atol=1e-5, rtol=1e-5) def test_ineichen_altitude(): @@ -184,7 +183,7 @@ def test_ineichen_altitude(): columns=['ghi', 'dni', 'dhi']) out = clearsky.ineichen(10, 1, 3, altitude=pd.Series(2000)) - assert_frame_equal(expected, out) + pd.testing.assert_frame_equal(expected, out, atol=1e-5, rtol=1e-5) def test_lookup_linke_turbidity(): @@ -196,7 +195,7 @@ def test_lookup_linke_turbidity(): np.array([3.11803278689, 3.11803278689, 3.13114754098]), index=times ) out = clearsky.lookup_linke_turbidity(times, 32.125, -110.875) - assert_series_equal(expected, out) + pd.testing.assert_series_equal(expected, out, atol=1e-5, rtol=1e-5) def test_lookup_linke_turbidity_leapyear(): @@ -208,7 +207,7 @@ def test_lookup_linke_turbidity_leapyear(): np.array([3.11803278689, 3.11803278689, 3.13114754098]), index=times ) out = clearsky.lookup_linke_turbidity(times, 32.125, -110.875) - assert_series_equal(expected, out) + pd.testing.assert_series_equal(expected, out, atol=1e-5, rtol=1e-5) def test_lookup_linke_turbidity_nointerp(): @@ -218,7 +217,7 @@ def test_lookup_linke_turbidity_nointerp(): expected = pd.Series(np.array([3., 3., 3.]), index=times) out = clearsky.lookup_linke_turbidity(times, 32.125, -110.875, interp_turbidity=False) - assert_series_equal(expected, out) + pd.testing.assert_series_equal(expected, out, atol=1e-5, rtol=1e-5) def test_lookup_linke_turbidity_months(): @@ -229,7 +228,7 @@ def test_lookup_linke_turbidity_months(): np.array([2.89918032787, 2.97540983607, 3.19672131148]), index=times ) out = clearsky.lookup_linke_turbidity(times, 32.125, -110.875) - assert_series_equal(expected, out) + pd.testing.assert_series_equal(expected, out, atol=1e-5, rtol=1e-5) def test_lookup_linke_turbidity_months_leapyear(): @@ -240,7 +239,7 @@ def test_lookup_linke_turbidity_months_leapyear(): np.array([2.89918032787, 2.97540983607, 3.19672131148]), index=times ) out = clearsky.lookup_linke_turbidity(times, 32.125, -110.875) - assert_series_equal(expected, out) + pd.testing.assert_series_equal(expected, out, atol=1e-5, rtol=1e-5) def test_lookup_linke_turbidity_nointerp_months(): @@ -250,14 +249,14 @@ def test_lookup_linke_turbidity_nointerp_months(): expected = pd.Series(np.array([2.85, 2.95, 3.]), index=times) out = clearsky.lookup_linke_turbidity(times, 32.125, -110.875, interp_turbidity=False) - assert_series_equal(expected, out) + pd.testing.assert_series_equal(expected, out, atol=1e-5, rtol=1e-5) # changing the dates shouldn't matter if interp=False times = pd.date_range(start='2014-04-05', end='2014-07-05', freq='1MS', tz='America/Phoenix', ) - pd.Timedelta(days=1) out = clearsky.lookup_linke_turbidity(times, 32.125, -110.875, interp_turbidity=False) - assert_series_equal(expected, out) + pd.testing.assert_series_equal(expected, out, atol=1e-5, rtol=1e-5) def test_haurwitz(): @@ -277,7 +276,7 @@ def test_haurwitz(): columns=['ghi'], index=apparent_solar_zenith) out = clearsky.haurwitz(data_in['apparent_zenith']) - assert_frame_equal(expected, out) + pd.testing.assert_frame_equal(expected, out, atol=1e-5, rtol=1e-5) def test_simplified_solis_scalar_elevation(): @@ -309,7 +308,7 @@ def test_simplified_solis_series_elevation(): expected = expected[['ghi', 'dni', 'dhi']] out = clearsky.simplified_solis(pd.Series(80)) - assert_frame_equal(expected, out) + pd.testing.assert_frame_equal(expected, out, atol=1e-5, rtol=1e-5) def test_simplified_solis_dni_extra(): @@ -318,7 +317,7 @@ def test_simplified_solis_dni_extra(): expected = expected[['ghi', 'dni', 'dhi']] out = clearsky.simplified_solis(80, dni_extra=pd.Series(1370)) - assert_frame_equal(expected, out) + pd.testing.assert_frame_equal(expected, out, atol=1e-5, rtol=1e-5) def test_simplified_solis_pressure(): @@ -331,7 +330,7 @@ def test_simplified_solis_pressure(): out = clearsky.simplified_solis( 80, pressure=pd.Series([95000, 98000, 101000])) - assert_frame_equal(expected, out) + pd.testing.assert_frame_equal(expected, out, atol=1e-5, rtol=1e-5) def test_simplified_solis_aod700(): @@ -346,7 +345,7 @@ def test_simplified_solis_aod700(): aod700 = pd.Series([0.0, 0.05, 0.1, 1, 10]) out = clearsky.simplified_solis(80, aod700=aod700) - assert_frame_equal(expected, out) + pd.testing.assert_frame_equal(expected, out, atol=1e-5, rtol=1e-5) def test_simplified_solis_precipitable_water(): @@ -361,7 +360,7 @@ def test_simplified_solis_precipitable_water(): out = clearsky.simplified_solis( 80, precipitable_water=pd.Series([0.0, 0.2, 0.5, 1.0, 5.0])) - assert_frame_equal(expected, out) + pd.testing.assert_frame_equal(expected, out, atol=1e-5, rtol=1e-5) def test_simplified_solis_small_scalar_pw(): @@ -473,7 +472,7 @@ def test_simplified_solis_nans_series(): out = clearsky.simplified_solis(apparent_elevation, aod700, precipitable_water, pressure, dni_extra) - assert_frame_equal(expected, out) + pd.testing.assert_frame_equal(expected, out, atol=1e-5, rtol=1e-5) def test_linke_turbidity_corners(): @@ -582,16 +581,26 @@ def test_detect_clearsky(detect_clearsky_data): expected, cs = detect_clearsky_data clear_samples = clearsky.detect_clearsky( expected['GHI'], cs['ghi'], times=cs.index, window_length=10) - assert_series_equal(expected['Clear or not'], clear_samples, - check_dtype=False, check_names=False) + pd.testing.assert_series_equal( + expected['Clear or not'], + clear_samples, + check_dtype=False, + check_names=False, + atol=1e-5, + rtol=1e-5) def test_detect_clearsky_defaults(detect_clearsky_data): expected, cs = detect_clearsky_data clear_samples = clearsky.detect_clearsky( expected['GHI'], cs['ghi']) - assert_series_equal(expected['Clear or not'], clear_samples, - check_dtype=False, check_names=False) + pd.testing.assert_series_equal( + expected['Clear or not'], + clear_samples, + check_dtype=False, + check_names=False, + atol=1e-5, + rtol=1e-5) def test_detect_clearsky_components(detect_clearsky_data): @@ -599,8 +608,13 @@ def test_detect_clearsky_components(detect_clearsky_data): clear_samples, components, alpha = clearsky.detect_clearsky( expected['GHI'], cs['ghi'], times=cs.index, window_length=10, return_components=True) - assert_series_equal(expected['Clear or not'], clear_samples, - check_dtype=False, check_names=False) + pd.testing.assert_series_equal( + expected['Clear or not'], + clear_samples, + check_dtype=False, + check_names=False, + atol=1e-5, + rtol=1e-5) assert isinstance(components, dict) assert np.allclose(alpha, 0.9633903181941296) @@ -615,8 +629,13 @@ def test_detect_clearsky_iterations(detect_clearsky_data): assert not clear_samples['2012-04-01 10:42:00':].any() # expected False clear_samples = clearsky.detect_clearsky( expected['GHI'], cs['ghi']*alpha, max_iterations=20) - assert_series_equal(expected['Clear or not'], clear_samples, - check_dtype=False, check_names=False) + pd.testing.assert_series_equal( + expected['Clear or not'], + clear_samples, + check_dtype=False, + check_names=False, + atol=1e-5, + rtol=1e-5) def test_detect_clearsky_kwargs(detect_clearsky_data): @@ -634,8 +653,13 @@ def test_detect_clearsky_window(detect_clearsky_data): expected['GHI'], cs['ghi'], window_length=3) expected = expected['Clear or not'].copy() expected.iloc[-3:] = 1 - assert_series_equal(expected, clear_samples, - check_dtype=False, check_names=False) + pd.testing.assert_series_equal( + expected, + clear_samples, + check_dtype=False, + check_names=False, + atol=1e-5, + rtol=1e-5) def test_detect_clearsky_time_interval(detect_clearsky_data): @@ -645,8 +669,13 @@ def test_detect_clearsky_time_interval(detect_clearsky_data): expected2 = expected.iloc[u] clear_samples = clearsky.detect_clearsky( expected2['GHI'], cs2['ghi'], window_length=6) - assert_series_equal(expected2['Clear or not'], clear_samples, - check_dtype=False, check_names=False) + pd.testing.assert_series_equal( + expected2['Clear or not'], + clear_samples, + check_dtype=False, + check_names=False, + atol=1e-5, + rtol=1e-5) def test_detect_clearsky_arrays(detect_clearsky_data): @@ -731,7 +760,11 @@ def test__line_length_windowed(detect_clearsky_helper_data): expected['line_length'] = sqt + sqt.shift(-1) result = clearsky._line_length_windowed( x, H, samples_per_window, sample_interval) - assert_series_equal(result, expected['line_length']) + pd.testing.assert_series_equal( + result, + expected['line_length'], + atol=1e-5, + rtol=1e-5) def test__max_diff_windowed(detect_clearsky_helper_data): @@ -740,7 +773,11 @@ def test__max_diff_windowed(detect_clearsky_helper_data): expected['max_diff'] = pd.Series( data=[np.nan, 3., 5., 7., 9., 11., np.nan], index=x.index) result = clearsky._max_diff_windowed(x, H, samples_per_window) - assert_series_equal(result, expected['max_diff']) + pd.testing.assert_series_equal( + result, + expected['max_diff'], + atol=1e-5, + rtol=1e-5) def test__calc_stats(detect_clearsky_helper_data): @@ -762,10 +799,26 @@ def test__calc_stats(detect_clearsky_helper_data): result = clearsky._calc_stats( x, samples_per_window, sample_interval, H) res_mean, res_max, res_slope_nstd, res_slope = result - assert_series_equal(res_mean, expected['mean']) - assert_series_equal(res_max, expected['max']) - assert_series_equal(res_slope_nstd, expected['slope_nstd']) - assert_series_equal(res_slope, expected['slope']) + pd.testing.assert_series_equal( + res_mean, + expected['mean'], + atol=1e-5, + rtol=1e-5) + pd.testing.assert_series_equal( + res_max, + expected['max'], + atol=1e-5, + rtol=1e-5) + pd.testing.assert_series_equal( + res_slope_nstd, + expected['slope_nstd'], + atol=1e-5, + rtol=1e-5) + pd.testing.assert_series_equal( + res_slope, + expected['slope'], + atol=1e-5, + rtol=1e-5) def test_bird(): diff --git a/tests/test_conftest.py b/tests/test_conftest.py index 7a177177ec..728280e2b9 100644 --- a/tests/test_conftest.py +++ b/tests/test_conftest.py @@ -1,43 +1,32 @@ +import pandas as pd import pytest -from tests import conftest +from .conftest import assert_index_equal -@pytest.mark.parametrize('function_name', ['assert_index_equal', - 'assert_series_equal', - 'assert_frame_equal']) -@pytest.mark.parametrize('pd_version', ['1.0.0', '1.1.0', '3.1.0']) -@pytest.mark.parametrize('check_less_precise', [True, False]) -def test__check_pandas_assert_kwargs(mocker, function_name, pd_version, - check_less_precise): - # test that conftest._check_pandas_assert_kwargs returns appropriate - # kwargs for the assert_x_equal functions +@pytest.mark.parametrize( + "version, expect_check_freq", + [("1.5.0", False), ("3.1.0", True)], +) +def test_assert_index_equal_check_freq( + monkeypatch, version, expect_check_freq): + """check_freq is only passed on pandas >= 3.1.0, where the kwarg exists. - # NOTE: be careful about mixing mocker.patch and pytest.MonkeyPatch! - # they do not coordinate their cleanups, so it is safest to only - # use one or the other. GH #1447 - - # patch the pandas assert; not interested in actually calling them, - # plus we want to spy on how they get called. - spy = mocker.patch('pandas.testing.' + function_name) - # patch pd.__version__ to exercise the two branches in - # conftest._check_pandas_assert_kwargs - mocker.patch('pandas.__version__', new=pd_version) - - # finally, run the function and check what args got passed to pandas: - assert_function = getattr(conftest, function_name) - args = [None, None] - assert_function(*args, check_less_precise=check_less_precise) - if pd_version in {'1.1.0', '3.1.0'}: - tol = 1e-3 if check_less_precise else 1e-5 - expected_kwargs = {'atol': tol, 'rtol': tol} + On older pandas, pandas.testing.assert_index_equal does not accept + check_freq, so passing it unconditionally would raise TypeError (and + would break the CI minimum environment, which pins pandas 1.5.0). + """ + left = pd.Index([1, 2, 3]) + right = pd.Index([1, 2, 3]) + monkeypatch.setattr(pd, "__version__", version) + calls = [] + monkeypatch.setattr( + pd.testing, "assert_index_equal", + lambda *args, **kwargs: calls.append(kwargs), + ) + assert_index_equal(left, right, atol=1e-5, rtol=1e-5) + assert len(calls) == 1 + if expect_check_freq: + assert calls[0].get("check_freq") is False else: - expected_kwargs = {'check_less_precise': check_less_precise} - if function_name == "assert_index_equal" and pd_version == '3.1.0': - # assert_index_equal in Pandas 3.1.0 warns: - # Pandas4Warning: assert_index_equal will check the 'freq' attribute - # by default in a future version; these freqs and None do not - # match. Pass check_freq=True or check_freq=False to silence - expected_kwargs['check_freq'] = False - - spy.assert_called_once_with(*args, **expected_kwargs) + assert "check_freq" not in calls[0] diff --git a/tests/test_iam.py b/tests/test_iam.py index 0287fd8fd2..822c740708 100644 --- a/tests/test_iam.py +++ b/tests/test_iam.py @@ -8,7 +8,6 @@ import pandas as pd import pytest -from .conftest import assert_series_equal from numpy.testing import assert_allclose from pvlib import iam as _iam @@ -23,7 +22,11 @@ def test_ashrae(): iam = _iam.ashrae(thetas, .05) assert_allclose(iam, expected, equal_nan=True) iam_series = _iam.ashrae(pd.Series(thetas)) - assert_series_equal(iam_series, pd.Series(expected)) + pd.testing.assert_series_equal( + iam_series, + pd.Series(expected), + atol=1e-5, + rtol=1e-5) def test_ashrae_scalar(): @@ -49,7 +52,7 @@ def test_physical(): aoi = pd.Series(aoi) iam = _iam.physical(aoi, 1.526, 0.002, 4) expected = pd.Series(expected) - assert_series_equal(iam, expected) + pd.testing.assert_series_equal(iam, expected, atol=1e-5, rtol=1e-5) def test_physical_n1_L0(): @@ -61,7 +64,7 @@ def test_physical_n1_L0(): aoi = pd.Series(aoi) expected = pd.Series(expected) iam = _iam.physical(aoi, n=1, L=0) - assert_series_equal(iam, expected) + pd.testing.assert_series_equal(iam, expected, atol=1e-5, rtol=1e-5) def test_physical_ar(): @@ -121,7 +124,7 @@ def test_martin_ruiz(): aoi = pd.Series(aoi) expected = pd.Series(expected) iam = _iam.martin_ruiz(aoi, a_r) - assert_series_equal(iam, expected) + pd.testing.assert_series_equal(iam, expected, atol=1e-5, rtol=1e-5) def test_martin_ruiz_exception(): @@ -169,8 +172,16 @@ def test_martin_ruiz_diffuse(): expected_sky = pd.Series(expected_sky, name='iam_sky') expected_gnd = pd.Series(expected_gnd, name='iam_ground') iam = _iam.martin_ruiz_diffuse(surface_tilt, a_r) - assert_series_equal(iam['sky'], expected_sky) - assert_series_equal(iam['ground'], expected_gnd) + pd.testing.assert_series_equal( + iam['sky'], + expected_sky, + atol=1e-5, + rtol=1e-5) + pd.testing.assert_series_equal( + iam['ground'], + expected_gnd, + atol=1e-5, + rtol=1e-5) def test_iam_interp(): @@ -201,7 +212,7 @@ def test_iam_interp(): expected = pd.Series(expected) iam_mult = np.multiply(0.9, iam_meas) iam = _iam.interp(aoi, aoi_meas, iam_mult, normalize=True) - assert_series_equal(iam, expected) + pd.testing.assert_series_equal(iam, expected, atol=1e-5, rtol=1e-5) # check beyond reference values aoi = np.array([-45, 0, 45, 85, 90, 95, 100, 105, 110]) @@ -291,7 +302,7 @@ def test_sapm(sapm_module_params, aoi, expected): out = _iam.sapm(aoi, sapm_module_params) if isinstance(aoi, pd.Series): - assert_series_equal(out, expected, check_less_precise=4) + pd.testing.assert_series_equal(out, expected, atol=1e-3, rtol=1e-3) else: assert_allclose(out, expected, atol=1e-4) @@ -394,7 +405,7 @@ def test_marion_integrate_series(region, N, expected): tilt = pd.Series([0, 20, 30], index=idx) expected = pd.Series(expected, index=idx) actual = _iam.marion_integrate(_iam.ashrae, tilt, region, N) - assert_series_equal(actual, expected) + pd.testing.assert_series_equal(actual, expected, atol=1e-5, rtol=1e-5) tilt.iloc[1] = np.nan expected.iloc[1] = np.nan @@ -434,7 +445,7 @@ def test_schlick(): # pandas Series actual = _iam.schlick(aoi) - assert_series_equal(expected, actual) + pd.testing.assert_series_equal(expected, actual, atol=1e-5, rtol=1e-5) def test_schlick_diffuse(): @@ -457,9 +468,16 @@ def test_schlick_diffuse(): # pandas Series idx = pd.date_range('2019-01-01', freq='h', periods=len(surface_tilt)) actual_iam = _iam.schlick_diffuse(pd.Series(surface_tilt, idx)) - assert_series_equal(pd.Series(expected_sky, idx), actual_iam['sky']) - assert_series_equal(pd.Series(expected_ground, idx), actual_iam['ground'], - rtol=1e-6) + pd.testing.assert_series_equal( + pd.Series(expected_sky, idx), + actual_iam['sky'], + atol=1e-5, + rtol=1e-5) + pd.testing.assert_series_equal( + pd.Series(expected_ground, idx), + actual_iam['ground'], + rtol=1e-5, + atol=1e-5) @pytest.mark.parametrize('source,source_params,target,expected', [ diff --git a/tests/test_inverter.py b/tests/test_inverter.py index 5794669ec9..4955d13f9d 100644 --- a/tests/test_inverter.py +++ b/tests/test_inverter.py @@ -1,7 +1,6 @@ import numpy as np import pandas as pd -from .conftest import assert_series_equal from numpy.testing import assert_allclose from .conftest import TESTS_DATA_DIR @@ -15,8 +14,11 @@ def test_adr(adr_inverter_parameters): pdcs = pd.Series([135, 1232, 1170, 420, 551]) pacs = inverter.adr(vdcs, pdcs, adr_inverter_parameters) - assert_series_equal(pacs, pd.Series([np.nan, 1161.5745, 1116.4459, - 382.6679, np.nan])) + pd.testing.assert_series_equal( + pacs, + pd.Series([np.nan, 1161.5745, 1116.4459, 382.6679, np.nan]), + atol=1e-5, + rtol=1e-5) def test_adr_vtol(adr_inverter_parameters): @@ -24,8 +26,11 @@ def test_adr_vtol(adr_inverter_parameters): pdcs = pd.Series([135, 1232, 1170, 420, 551]) pacs = inverter.adr(vdcs, pdcs, adr_inverter_parameters, vtol=0.20) - assert_series_equal(pacs, pd.Series([104.8223, 1161.5745, 1116.4459, - 382.6679, 513.3385])) + pd.testing.assert_series_equal( + pacs, + pd.Series([104.8223, 1161.5745, 1116.4459, 382.6679, 513.3385]), + atol=1e-5, + rtol=1e-5) def test_adr_float(adr_inverter_parameters): @@ -53,7 +58,11 @@ def test_sandia(cec_inverter_parameters): pdcs = idcs * vdcs pacs = inverter.sandia(vdcs, pdcs, cec_inverter_parameters) - assert_series_equal(pacs, pd.Series([-0.020000, 132.004308, 250.000000])) + pd.testing.assert_series_equal( + pacs, + pd.Series([-0.020000, 132.004308, 250.000000]), + atol=1e-5, + rtol=1e-5) def test_sandia_float(cec_inverter_parameters): @@ -97,7 +106,11 @@ def test_sandia_Pnt_micro(): pdcs = idcs * vdcs pacs = inverter.sandia(vdcs, pdcs, inverter_parameters) - assert_series_equal(pacs, pd.Series([-0.043, 132.545914746, 240.0])) + pd.testing.assert_series_equal( + pacs, + pd.Series([-0.043, 132.545914746, 240.0]), + atol=1e-5, + rtol=1e-5) def test_sandia_multi(cec_inverter_parameters): @@ -106,11 +119,19 @@ def test_sandia_multi(cec_inverter_parameters): pdcs = idcs * vdcs pacs = inverter.sandia_multi((vdcs, vdcs), (pdcs, pdcs), cec_inverter_parameters) - assert_series_equal(pacs, pd.Series([-0.020000, 132.004278, 250.000000])) + pd.testing.assert_series_equal( + pacs, + pd.Series([-0.020000, 132.004278, 250.000000]), + atol=1e-5, + rtol=1e-5) # with lists instead of tuples pacs = inverter.sandia_multi([vdcs, vdcs], [pdcs, pdcs], cec_inverter_parameters) - assert_series_equal(pacs, pd.Series([-0.020000, 132.004278, 250.000000])) + pd.testing.assert_series_equal( + pacs, + pd.Series([-0.020000, 132.004278, 250.000000]), + atol=1e-5, + rtol=1e-5) # with arrays instead of tuples pacs = inverter.sandia_multi(np.array([vdcs, vdcs]), np.array([pdcs, pdcs]), @@ -168,7 +189,7 @@ def test_pvwatts_series(): pdc0 = 100 expected = pd.Series(np.array([np.nan, 0., 47.608436, 95.])) out = inverter.pvwatts(pdc, pdc0, 0.95) - assert_series_equal(expected, out) + pd.testing.assert_series_equal(expected, out, atol=1e-5, rtol=1e-5) def test_pvwatts_multi(): @@ -184,10 +205,18 @@ def test_pvwatts_multi(): # with Series pdc = pd.Series(pdc) out = inverter.pvwatts_multi((pdc, pdc), pdc0, 0.95) - assert_series_equal(pd.Series(expected), out) + pd.testing.assert_series_equal( + pd.Series(expected), + out, + atol=1e-5, + rtol=1e-5) # with list instead of tuple out = inverter.pvwatts_multi([pdc, pdc], pdc0, 0.95) - assert_series_equal(pd.Series(expected), out) + pd.testing.assert_series_equal( + pd.Series(expected), + out, + atol=1e-5, + rtol=1e-5) INVERTER_TEST_MEAS = TESTS_DATA_DIR / 'inverter_fit_snl_meas.csv' diff --git a/tests/test_irradiance.py b/tests/test_irradiance.py index 1ee62db6f8..7a4dea1f51 100644 --- a/tests/test_irradiance.py +++ b/tests/test_irradiance.py @@ -11,11 +11,8 @@ from pvlib import irradiance, albedo from .conftest import ( - assert_frame_equal, - assert_series_equal, requires_ephem, - requires_numba, -) + requires_numba) from pvlib._deprecation import pvlibDeprecationWarning @@ -142,7 +139,11 @@ def test_get_ground_diffuse_albedo_series(times): 45, pd.Series(1000, index=times), albedo) expected = albedo * 0.5 * (1 - np.sqrt(2) / 2.) * 1000 expected.name = 'poa_ground_diffuse' - assert_series_equal(ground_irrad, expected) + pd.testing.assert_series_equal( + ground_irrad, + expected, + atol=1e-5, + rtol=1e-5) def test_grounddiffuse_albedo_invalid_surface(irrad_data): @@ -178,7 +179,7 @@ def test_isotropic_components(irrad_data): # pandas result = irradiance.isotropic( 40, irrad_data['dhi'], return_components=True) - assert_frame_equal(result, expected, check_less_precise=4) + pd.testing.assert_frame_equal(result, expected, atol=1e-3, rtol=1e-3) # numpy result = irradiance.isotropic( 40, irrad_data['dhi'].to_numpy(), return_components=True) @@ -247,7 +248,7 @@ def test_haydavies_components(irrad_data, ephem_data, dni_et): 40, 180, irrad_data['dhi'], irrad_data['dni'], dni_et, ephem_data['apparent_zenith'], ephem_data['azimuth'], return_components=True) - assert_frame_equal(result, expected, check_less_precise=4) + pd.testing.assert_frame_equal(result, expected, atol=1e-3, rtol=1e-3) # numpy result = irradiance.haydavies( 40, 180, irrad_data['dhi'].values, irrad_data['dni'].values, dni_et, @@ -290,7 +291,7 @@ def test_reindl_components(irrad_data, ephem_data, dni_et): 40, 180, irrad_data['dhi'], irrad_data['dni'], irrad_data['ghi'], dni_et, ephem_data['apparent_zenith'], ephem_data['azimuth'], return_components=True) - assert_frame_equal(result, expected, check_less_precise=4) + pd.testing.assert_frame_equal(result, expected, atol=1e-3, rtol=1e-3) # numpy result = irradiance.reindl( 40, 180, irrad_data['dhi'].to_numpy(), irrad_data['dni'].to_numpy(), @@ -329,7 +330,7 @@ def test_perez(irrad_data, ephem_data, dni_et, relative_airmass): expected = pd.Series(np.array( [0., 31.46046871, np.nan, 45.45539877]), index=irrad_data.index) - assert_series_equal(out, expected, check_less_precise=2) + pd.testing.assert_series_equal(out, expected, atol=1e-3, rtol=1e-3) def test_perez_driesse(irrad_data, ephem_data, dni_et, relative_airmass): @@ -341,7 +342,7 @@ def test_perez_driesse(irrad_data, ephem_data, dni_et, relative_airmass): expected = pd.Series(np.array( [0., 29.991, np.nan, 47.397]), index=irrad_data.index) - assert_series_equal(out, expected, check_less_precise=2) + pd.testing.assert_series_equal(out, expected, atol=1e-3, rtol=1e-3) def test_perez_driesse_airmass(irrad_data, ephem_data, dni_et): @@ -354,7 +355,7 @@ def test_perez_driesse_airmass(irrad_data, ephem_data, dni_et): expected = pd.Series(np.array( [0., 29.991, np.nan, 47.397]), index=irrad_data.index) - assert_series_equal(out, expected, check_less_precise=2) + pd.testing.assert_series_equal(out, expected, atol=1e-3, rtol=1e-3) def test_perez_components(irrad_data, ephem_data, dni_et, relative_airmass): @@ -378,8 +379,12 @@ def test_perez_components(irrad_data, ephem_data, dni_et, relative_airmass): sum_components = out.iloc[:, 1:].sum(axis=1) sum_components.name = 'poa_sky_diffuse' - assert_frame_equal(out, expected, check_less_precise=2) - assert_series_equal(sum_components, expected_for_sum, check_less_precise=2) + pd.testing.assert_frame_equal(out, expected, atol=1e-3, rtol=1e-3) + pd.testing.assert_series_equal( + sum_components, + expected_for_sum, + atol=1e-3, + rtol=1e-3) def test_perez_driesse_components(irrad_data, ephem_data, dni_et, @@ -405,8 +410,12 @@ def test_perez_driesse_components(irrad_data, ephem_data, dni_et, sum_components = out.iloc[:, 1:].sum(axis=1) sum_components.name = 'poa_sky_diffuse' - assert_frame_equal(out, expected, check_less_precise=2) - assert_series_equal(sum_components, expected_for_sum, check_less_precise=2) + pd.testing.assert_frame_equal(out, expected, atol=1e-3, rtol=1e-3) + pd.testing.assert_series_equal( + sum_components, + expected_for_sum, + atol=1e-3, + rtol=1e-3) def test_perez_negative_horizon(): @@ -452,8 +461,12 @@ def test_perez_negative_horizon(): sum_components = out.iloc[:, 1:].sum(axis=1) sum_components.name = 'poa_sky_diffuse' - assert_frame_equal(out, expected, check_less_precise=2) - assert_series_equal(sum_components, expected_for_sum, check_less_precise=2) + pd.testing.assert_frame_equal(out, expected, atol=1e-3, rtol=1e-3) + pd.testing.assert_series_equal( + sum_components, + expected_for_sum, + atol=1e-3, + rtol=1e-3) def test_perez_arrays(irrad_data, ephem_data, dni_et, relative_airmass): @@ -557,7 +570,7 @@ def test_get_sky_diffuse_missing_airmass(irrad_data, ephem_data, dni_et): expected = pd.Series(np.array( [0., 31.46046871, np.nan, 45.45539877]), index=irrad_data.index) - assert_series_equal(out, expected, check_less_precise=2) + pd.testing.assert_series_equal(out, expected, atol=1e-3, rtol=1e-3) def test_campbell_norman(): @@ -568,7 +581,7 @@ def test_campbell_norman(): out = irradiance.campbell_norman( pd.Series([10]), pd.Series([0.5]), pd.Series([109764.21013135818]), dni_extra=1400) - assert_frame_equal(out, expected) + pd.testing.assert_frame_equal(out, expected, atol=1e-5, rtol=1e-5) def test_get_total_irradiance(irrad_data, ephem_data, dni_et, @@ -715,7 +728,7 @@ def test_poa_components(irrad_data, ephem_data, dni_et, relative_airmass): columns=['poa_global', 'poa_direct', 'poa_diffuse', 'poa_sky_diffuse', 'poa_ground_diffuse'], index=irrad_data.index) - assert_frame_equal(out, expected) + pd.testing.assert_frame_equal(out, expected, atol=1e-5, rtol=1e-5) def test_poa_components_diffuse_components_perez(irrad_data, ephem_data, @@ -743,7 +756,7 @@ def test_poa_components_diffuse_components_perez(irrad_data, ephem_data, 'poa_ground_diffuse', 'poa_isotropic', 'poa_circumsolar', 'poa_horizon'], index=irrad_data.index) - assert_frame_equal(out, expected) + pd.testing.assert_frame_equal(out, expected, atol=1e-5, rtol=1e-5) def test_poa_components_diffuse_components_isotropic(irrad_data, ephem_data, @@ -768,7 +781,7 @@ def test_poa_components_diffuse_components_isotropic(irrad_data, ephem_data, columns=['poa_global', 'poa_direct', 'poa_diffuse', 'poa_sky_diffuse', 'poa_ground_diffuse', 'poa_isotropic'], index=irrad_data.index) - assert_frame_equal(out, expected) + pd.testing.assert_frame_equal(out, expected, atol=1e-5, rtol=1e-5) @pytest.mark.parametrize('pressure,expected', [ @@ -789,8 +802,8 @@ def test_disc_value(pressure, expected): out = irradiance.disc(ghi, zenith, times, pressure=pressure) expected_values = np.array(expected) expected = pd.DataFrame(expected_values, columns=columns, index=times) - # check the pandas dataframe. check_less_precise is weird - assert_frame_equal(out, expected, check_less_precise=True) + # check the pandas dataframe with loose (1e-3) tolerances + pd.testing.assert_frame_equal(out, expected, atol=1e-3, rtol=1e-3) # use np.assert_allclose to check values more clearly assert_allclose(out.values, expected_values, atol=1e-5) @@ -806,7 +819,7 @@ def test_disc_overirradiance(): expected = pd.DataFrame(np.array( [[8.72544336e+02, 1.00000000e+00, 9.99493933e-01]]), columns=columns, index=times) - assert_frame_equal(out, expected) + pd.testing.assert_frame_equal(out, expected, atol=1e-5, rtol=1e-5) def test_disc_min_cos_zenith_max_zenith(): @@ -818,7 +831,7 @@ def test_disc_min_cos_zenith_max_zenith(): expected = pd.DataFrame(np.array( [[0.00000000e+00, 1.16046346e-02, 12.0]]), columns=columns, index=times) - assert_frame_equal(out, expected) + pd.testing.assert_frame_equal(out, expected, atol=1e-5, rtol=1e-5) # max_zenith and/or max_airmass keep these results reasonable out = irradiance.disc(ghi=1.0, solar_zenith=89.99, datetime_or_doy=times, @@ -826,7 +839,7 @@ def test_disc_min_cos_zenith_max_zenith(): expected = pd.DataFrame(np.array( [[0.00000000e+00, 1.0, 12.0]]), columns=columns, index=times) - assert_frame_equal(out, expected) + pd.testing.assert_frame_equal(out, expected, atol=1e-5, rtol=1e-5) # still get reasonable values because of max_airmass=12 limit out = irradiance.disc(ghi=1.0, solar_zenith=89.99, datetime_or_doy=times, @@ -834,7 +847,7 @@ def test_disc_min_cos_zenith_max_zenith(): expected = pd.DataFrame(np.array( [[0., 1.16046346e-02, 12.0]]), columns=columns, index=times) - assert_frame_equal(out, expected) + pd.testing.assert_frame_equal(out, expected, atol=1e-5, rtol=1e-5) # still get reasonable values because of max_airmass=12 limit out = irradiance.disc(ghi=1.0, solar_zenith=89.99, datetime_or_doy=times, @@ -842,7 +855,7 @@ def test_disc_min_cos_zenith_max_zenith(): expected = pd.DataFrame(np.array( [[277.50185968, 1.0, 12.0]]), columns=columns, index=times) - assert_frame_equal(out, expected) + pd.testing.assert_frame_equal(out, expected, atol=1e-5, rtol=1e-5) # max_zenith keeps this result reasonable out = irradiance.disc(ghi=1.0, solar_zenith=89.99, datetime_or_doy=times, @@ -850,7 +863,7 @@ def test_disc_min_cos_zenith_max_zenith(): expected = pd.DataFrame(np.array( [[0.00000000e+00, 1.0, 36.39544757]]), columns=columns, index=times) - assert_frame_equal(out, expected) + pd.testing.assert_frame_equal(out, expected, atol=1e-5, rtol=1e-5) # allow zenith to be close to 90 and airmass to be infinite # and we get crazy values @@ -859,7 +872,7 @@ def test_disc_min_cos_zenith_max_zenith(): expected = pd.DataFrame(np.array( [[6.68577449e+03, 1.16046346e-02, 3.63954476e+01]]), columns=columns, index=times) - assert_frame_equal(out, expected) + pd.testing.assert_frame_equal(out, expected, atol=1e-5, rtol=1e-5) # allow min cos zenith to be 0, zenith to be close to 90, # and airmass to be very big and we get even higher DNI values @@ -868,7 +881,7 @@ def test_disc_min_cos_zenith_max_zenith(): expected = pd.DataFrame(np.array( [[7.21238390e+03, 1., 3.63954476e+01]]), columns=columns, index=times) - assert_frame_equal(out, expected) + pd.testing.assert_frame_equal(out, expected, atol=1e-5, rtol=1e-5) def test_dirint_value(): @@ -901,7 +914,7 @@ def test_delta_kt_prime_interior_nan(): kt_prime = pd.Series([0.5, 0.6, np.nan, 0.7, 0.4], index=times) result = irradiance._delta_kt_prime_dirint(kt_prime, True, times) expected = pd.Series([0.1, 0.1, np.nan, 0.3, 0.3], index=times) - assert_series_equal(result, expected) + pd.testing.assert_series_equal(result, expected, atol=1e-5, rtol=1e-5) def test_dirint_tdew(): @@ -943,25 +956,25 @@ def test_dirint_min_cos_zenith_max_zenith(): out = irradiance.dirint(ghi, solar_zenith, times) expected = pd.Series([0.0, 0.0], index=times, name='dni') - assert_series_equal(out, expected) + pd.testing.assert_series_equal(out, expected, atol=1e-5, rtol=1e-5) out = irradiance.dirint(ghi, solar_zenith, times, min_cos_zenith=0) expected = pd.Series([0.0, 0.0], index=times, name='dni') - assert_series_equal(out, expected) + pd.testing.assert_series_equal(out, expected, atol=1e-5, rtol=1e-5) out = irradiance.dirint(ghi, solar_zenith, times, max_zenith=90) expected = pd.Series([0.0, 0.0], index=times, name='dni') - assert_series_equal(out, expected, check_less_precise=True) + pd.testing.assert_series_equal(out, expected, atol=1e-3, rtol=1e-3) out = irradiance.dirint(ghi, solar_zenith, times, min_cos_zenith=0, max_zenith=90) expected = pd.Series([0.0, 144.264507], index=times, name='dni') - assert_series_equal(out, expected, check_less_precise=True) + pd.testing.assert_series_equal(out, expected, atol=1e-3, rtol=1e-3) out = irradiance.dirint(ghi, solar_zenith, times, min_cos_zenith=0, max_zenith=100) expected = pd.Series([0.0, 144.264507], index=times, name='dni') - assert_series_equal(out, expected, check_less_precise=True) + pd.testing.assert_series_equal(out, expected, atol=1e-3, rtol=1e-3) def test_ghi_from_poa_driesse(mocker): @@ -1052,7 +1065,7 @@ def test_gti_dirint(): [931.04078010, 695.94965324, 277.06172442]]), columns=expected_col_order, index=times) - assert_frame_equal(output, expected) + pd.testing.assert_frame_equal(output, expected, atol=1e-5, rtol=1e-5) # test ignore calculate_gt_90 output = irradiance.gti_dirint( @@ -1062,7 +1075,7 @@ def test_gti_dirint(): expected_no_90 = expected.copy() expected_no_90.iloc[0, :] = np.nan - assert_frame_equal(output, expected_no_90) + pd.testing.assert_frame_equal(output, expected_no_90, atol=1e-5, rtol=1e-5) # test pressure input pressure = 93193. @@ -1076,7 +1089,7 @@ def test_gti_dirint(): [932.46756378, 648.05001357, 323.49974813]]), columns=expected_col_order, index=times) - assert_frame_equal(output, expected) + pd.testing.assert_frame_equal(output, expected, atol=1e-5, rtol=1e-5) # test albedo input albedo = 0.05 @@ -1090,7 +1103,7 @@ def test_gti_dirint(): [941.7943404, 727.50552952, 258.16276278]]), columns=expected_col_order, index=times) - assert_frame_equal(output, expected) + pd.testing.assert_frame_equal(output, expected, atol=1e-5, rtol=1e-5) # test with albedo as a Series albedo = pd.Series(0.05, index=times) @@ -1098,7 +1111,7 @@ def test_gti_dirint(): poa_global, aoi, zenith, azimuth, times, surface_tilt, surface_azimuth, albedo=albedo) - assert_frame_equal(output, expected) + pd.testing.assert_frame_equal(output, expected, atol=1e-5, rtol=1e-5) # test temp_dew input temp_dew = np.array([70, 80, 20]) @@ -1112,7 +1125,7 @@ def test_gti_dirint(): [931.79627208, 689.81549269, 283.5817439]]), columns=expected_col_order, index=times) - assert_frame_equal(output, expected) + pd.testing.assert_frame_equal(output, expected, atol=1e-5, rtol=1e-5) def test_gti_dirint_data_error(): @@ -1145,7 +1158,11 @@ def test_erbs(): out = irradiance.erbs(ghi, zenith, index) - assert_frame_equal(np.round(out, 0), np.round(expected, 0)) + pd.testing.assert_frame_equal( + np.round(out, 0), + np.round(expected, 0), + atol=1e-5, + rtol=1e-5) def test_erbs_driesse(): @@ -1162,14 +1179,22 @@ def test_erbs_driesse(): out = irradiance.erbs_driesse(ghi, zenith, index) - assert_frame_equal(np.round(out, 0), np.round(expected, 0)) + pd.testing.assert_frame_equal( + np.round(out, 0), + np.round(expected, 0), + atol=1e-5, + rtol=1e-5) # test with the new optional dni_extra argument dni_extra = irradiance.get_extra_radiation(index) out = irradiance.erbs_driesse(ghi, zenith, dni_extra=dni_extra) - assert_frame_equal(np.round(out, 0), np.round(expected, 0)) + pd.testing.assert_frame_equal( + np.round(out, 0), + np.round(expected, 0), + atol=1e-5, + rtol=1e-5) # test for required inputs with pytest.raises(ValueError): @@ -1220,7 +1245,7 @@ def test_erbs_min_cos_zenith_max_zenith(): expected = pd.DataFrame(np.array( [[0., 1., 1.]]), columns=columns, index=times) - assert_frame_equal(out, expected) + pd.testing.assert_frame_equal(out, expected, atol=1e-5, rtol=1e-5) # 4-5 9s will produce bad behavior without max_zenith limit out = irradiance.erbs(ghi=1.0, zenith=89.99999, @@ -1228,7 +1253,7 @@ def test_erbs_min_cos_zenith_max_zenith(): expected = pd.DataFrame(np.array( [[6.00115286e+03, 9.98952601e-01, 1.16377640e-02]]), columns=columns, index=times) - assert_frame_equal(out, expected) + pd.testing.assert_frame_equal(out, expected, atol=1e-5, rtol=1e-5) # 1-2 9s will produce bad behavior without either limit out = irradiance.erbs(ghi=1.0, zenith=89.99, datetime_or_doy=times, @@ -1236,14 +1261,14 @@ def test_erbs_min_cos_zenith_max_zenith(): expected = pd.DataFrame(np.array( [[4.78419761e+03, 1.65000000e-01, 1.00000000e+00]]), columns=columns, index=times) - assert_frame_equal(out, expected) + pd.testing.assert_frame_equal(out, expected, atol=1e-5, rtol=1e-5) # check default behavior under hardest condition out = irradiance.erbs(ghi=1.0, zenith=90, datetime_or_doy=times) expected = pd.DataFrame(np.array( [[0., 1., 0.01163776]]), columns=columns, index=times) - assert_frame_equal(out, expected) + pd.testing.assert_frame_equal(out, expected, atol=1e-5, rtol=1e-5) def test_erbs_all_scalar(): @@ -1312,22 +1337,22 @@ def test_dirindex_min_cos_zenith_max_zenith(): out = irradiance.dirindex(ghi, ghi_clearsky, dni_clear, solar_zenith, times) expected = pd.Series([nan, nan], index=times) - assert_series_equal(out, expected) + pd.testing.assert_series_equal(out, expected, atol=1e-5, rtol=1e-5) out = irradiance.dirindex(ghi, ghi_clearsky, dni_clear, solar_zenith, times, min_cos_zenith=0) expected = pd.Series([nan, nan], index=times) - assert_series_equal(out, expected) + pd.testing.assert_series_equal(out, expected, atol=1e-5, rtol=1e-5) out = irradiance.dirindex(ghi, ghi_clearsky, dni_clear, solar_zenith, times, max_zenith=90) expected = pd.Series([nan, nan], index=times) - assert_series_equal(out, expected) + pd.testing.assert_series_equal(out, expected, atol=1e-5, rtol=1e-5) out = irradiance.dirindex(ghi, ghi_clearsky, dni_clear, solar_zenith, times, min_cos_zenith=0, max_zenith=100) expected = pd.Series([nan, 5.], index=times) - assert_series_equal(out, expected) + pd.testing.assert_series_equal(out, expected, atol=1e-5, rtol=1e-5) def test_dirint_array_inputs(): @@ -1363,14 +1388,18 @@ def test_dni(): dni = irradiance.dni(ghi, dhi, zenith, dni_clear=dni_clear, clearsky_tolerance=2) - assert_series_equal(dni, - pd.Series([float('nan'), float('nan'), 400, - 146.190220008, 573.685662283])) + pd.testing.assert_series_equal( + dni, + pd.Series([float('nan'), float('nan'), 400, + 146.190220008, 573.685662283]), + atol=1e-5, rtol=1e-5) dni = irradiance.dni(ghi, dhi, zenith) - assert_series_equal(dni, - pd.Series([float('nan'), float('nan'), 573.685662283, - 146.190220008, 573.685662283])) + pd.testing.assert_series_equal( + dni, + pd.Series([float('nan'), float('nan'), 573.685662283, + 146.190220008, 573.685662283]), + atol=1e-5, rtol=1e-5) @pytest.mark.parametrize( @@ -1462,7 +1491,7 @@ def test_clearsky_index(): ghi_modeled = pd.Series([500, 1000], index=times) out = irradiance.clearsky_index(ghi_measured, ghi_modeled) expected = pd.Series([0.2, 0.5], index=times) - assert_series_equal(out, expected) + pd.testing.assert_series_equal(out, expected, atol=1e-5, rtol=1e-5) def test_clearness_index(): @@ -1519,7 +1548,7 @@ def test_clearness_index(): extra_radiation = pd.Series([1360, 1400], index=times) out = irradiance.clearness_index(ghi, solar_zenith, extra_radiation) expected = pd.Series([0, 0.714285714286], index=times) - assert_series_equal(out, expected) + pd.testing.assert_series_equal(out, expected, atol=1e-5, rtol=1e-5) def test_clearness_index_zenith_independent(airmass_kt): @@ -1553,7 +1582,7 @@ def test_clearness_index_zenith_independent(airmass_kt): out = irradiance.clearness_index_zenith_independent(clearness_index, airmass) expected = pd.Series([np.nan, 0.553744437562], index=times) - assert_series_equal(out, expected) + pd.testing.assert_series_equal(out, expected, atol=1e-5, rtol=1e-5) def test_complete_irradiance(): @@ -1585,7 +1614,7 @@ def test_complete_irradiance(): dni_clear=clearsky.dni) # Assert that the ghi, dhi, and dni series match the original dataframe # values - assert_frame_equal(complete_df, i) + pd.testing.assert_frame_equal(complete_df, i, atol=1e-5, rtol=1e-5) # Test scenario where GHI is generated via component sum equation complete_df = irradiance.complete_irradiance( solar_position.apparent_zenith, @@ -1595,7 +1624,7 @@ def test_complete_irradiance(): dni_clear=clearsky.dni) # Assert that the ghi, dhi, and dni series match the original dataframe # values - assert_frame_equal(complete_df, i) + pd.testing.assert_frame_equal(complete_df, i, atol=1e-5, rtol=1e-5) # Test scenario where DHI is generated via component sum equation complete_df = irradiance.complete_irradiance( solar_position.apparent_zenith, @@ -1605,7 +1634,7 @@ def test_complete_irradiance(): dni_clear=clearsky.dni) # Assert that the ghi, dhi, and dni series match the original dataframe # values - assert_frame_equal(complete_df, i) + pd.testing.assert_frame_equal(complete_df, i, atol=1e-5, rtol=1e-5) # Test scenario where all parameters are passed (throw error) with pytest.raises(ValueError): irradiance.complete_irradiance(solar_position.apparent_zenith, @@ -1636,7 +1665,7 @@ def test_louche(): out = irradiance.louche(ghi, zenith, index) - assert_frame_equal(out, expected) + pd.testing.assert_frame_equal(out, expected, atol=1e-5, rtol=1e-5) def test_SURFACE_ALBEDOS_deprecated(): diff --git a/tests/test_location.py b/tests/test_location.py index b147f4ab2a..43479a86d9 100644 --- a/tests/test_location.py +++ b/tests/test_location.py @@ -5,8 +5,7 @@ import numpy as np from numpy import nan import pandas as pd -from .conftest import (assert_frame_equal, assert_index_equal, - assert_series_equal, fail_on_pvlib_version) +from .conftest import assert_index_equal, fail_on_pvlib_version from pvlib._deprecation import pvlibDeprecationWarning import pytest @@ -126,7 +125,11 @@ def test_get_clearsky(mocker, times): m = mocker.spy(pvlib.clearsky, 'ineichen') out = tus.get_clearsky(times) assert m.call_count == 1 - assert_index_equal(out.index, times) + assert_index_equal( + out.index, + times, + atol=1e-5, + rtol=1e-5) # check that values are 0 before sunrise and after sunset assert out.iloc[0, :].sum().sum() == 0 assert out.iloc[-1:, :].sum().sum() == 0 @@ -143,7 +146,11 @@ def test_get_clearsky_ineichen_supply_linke(mocker): out = tus.get_clearsky(times, linke_turbidity=3) # we only care that the LT is passed in this test pvlib.clearsky.ineichen.assert_called_once_with(ANY, ANY, 3, ANY, ANY) - assert_index_equal(out.index, times) + assert_index_equal( + out.index, + times, + atol=1e-5, + rtol=1e-5) # check that values are 0 before sunrise and after sunset assert out.iloc[0:2, :].sum().sum() == 0 assert out.iloc[-2:, :].sum().sum() == 0 @@ -163,7 +170,7 @@ def test_get_clearsky_haurwitz(times): [ 0. ]]), columns=['ghi'], index=times) - assert_frame_equal(expected, clearsky) + pd.testing.assert_frame_equal(expected, clearsky, atol=1e-5, rtol=1e-5) def test_get_clearsky_simplified_solis(times): @@ -178,7 +185,7 @@ def test_get_clearsky_simplified_solis(times): columns=['dhi', 'dni', 'ghi'], index=times) expected = expected[['ghi', 'dni', 'dhi']] - assert_frame_equal(expected, clearsky, check_less_precise=2) + pd.testing.assert_frame_equal(expected, clearsky, atol=1e-3, rtol=1e-3) def test_get_clearsky_simplified_solis_apparent_elevation(times): @@ -196,7 +203,7 @@ def test_get_clearsky_simplified_solis_apparent_elevation(times): columns=['dhi', 'dni', 'ghi'], index=times) expected = expected[['ghi', 'dni', 'dhi']] - assert_frame_equal(expected, clearsky, check_less_precise=2) + pd.testing.assert_frame_equal(expected, clearsky, atol=1e-3, rtol=1e-3) def test_get_clearsky_simplified_solis_dni_extra(times): @@ -212,7 +219,7 @@ def test_get_clearsky_simplified_solis_dni_extra(times): columns=['dhi', 'dni', 'ghi'], index=times) expected = expected[['ghi', 'dni', 'dhi']] - assert_frame_equal(expected, clearsky) + pd.testing.assert_frame_equal(expected, clearsky, atol=1e-5, rtol=1e-5) def test_get_clearsky_simplified_solis_pressure(times): @@ -228,7 +235,7 @@ def test_get_clearsky_simplified_solis_pressure(times): columns=['dhi', 'dni', 'ghi'], index=times) expected = expected[['ghi', 'dni', 'dhi']] - assert_frame_equal(expected, clearsky, check_less_precise=2) + pd.testing.assert_frame_equal(expected, clearsky, atol=1e-3, rtol=1e-3) def test_get_clearsky_simplified_solis_aod_pw(times): @@ -244,7 +251,7 @@ def test_get_clearsky_simplified_solis_aod_pw(times): columns=['dhi', 'dni', 'ghi'], index=times) expected = expected[['ghi', 'dni', 'dhi']] - assert_frame_equal(expected, clearsky, check_less_precise=2) + pd.testing.assert_frame_equal(expected, clearsky, atol=1e-3, rtol=1e-3) def test_get_clearsky_valueerror(times): @@ -261,7 +268,7 @@ def test_from_tmy_3(): assert loc.name is not None assert loc.altitude != 0 assert loc.tz != 'UTC' - assert_frame_equal(loc.weather, data) + pd.testing.assert_frame_equal(loc.weather, data, atol=1e-5, rtol=1e-5) def test_from_tmy_2(): @@ -272,7 +279,7 @@ def test_from_tmy_2(): assert loc.name is not None assert loc.altitude != 0 assert loc.tz != 'UTC' - assert_frame_equal(loc.weather, data) + pd.testing.assert_frame_equal(loc.weather, data, atol=1e-5, rtol=1e-5) def test_from_epw(): @@ -283,7 +290,7 @@ def test_from_epw(): assert loc.name is not None assert loc.altitude != 0 assert loc.tz != 'UTC' - assert_frame_equal(loc.weather, data) + pd.testing.assert_frame_equal(loc.weather, data, atol=1e-5, rtol=1e-5) def test_get_solarposition(expected_solpos, golden_mst): @@ -293,7 +300,11 @@ def test_get_solarposition(expected_solpos, golden_mst): ephem_data = np.round(ephem_data, 3) expected_solpos.index = times expected_solpos = np.round(expected_solpos, 3) - assert_frame_equal(expected_solpos, ephem_data[expected_solpos.columns]) + pd.testing.assert_frame_equal( + expected_solpos, + ephem_data[expected_solpos.columns], + atol=1e-5, + rtol=1e-5) def test_get_airmass(times): @@ -307,7 +318,7 @@ def test_get_airmass(times): [ nan, nan]]), columns=['airmass_relative', 'airmass_absolute'], index=times) - assert_frame_equal(expected, airmass) + pd.testing.assert_frame_equal(expected, airmass, atol=1e-5, rtol=1e-5) airmass = tus.get_airmass(times, model='young1994') expected = pd.DataFrame(data=np.array( @@ -318,7 +329,7 @@ def test_get_airmass(times): [ nan, nan]]), columns=['airmass_relative', 'airmass_absolute'], index=times) - assert_frame_equal(expected, airmass) + pd.testing.assert_frame_equal(expected, airmass, atol=1e-5, rtol=1e-5) @pytest.mark.parametrize('model,zenith_column', [ @@ -339,8 +350,8 @@ def test_get_airmass_models(times, model, zenith_column): airmass = tus.get_airmass(solar_position=solar_position, model=model) expected = atmosphere.get_relative_airmass(solar_position[zenith_column], model) - assert_series_equal(airmass['airmass_relative'], expected, - check_names=False) + pd.testing.assert_series_equal(airmass['airmass_relative'], expected, + check_names=False, atol=1e-5, rtol=1e-5) def test_get_airmass_valueerror(times): diff --git a/tests/test_modelchain.py b/tests/test_modelchain.py index 6b443ac0fc..77e4d8cb52 100644 --- a/tests/test_modelchain.py +++ b/tests/test_modelchain.py @@ -8,7 +8,6 @@ from pvlib.pvsystem import PVSystem from pvlib.location import Location -from .conftest import assert_series_equal, assert_frame_equal import pytest @@ -356,7 +355,7 @@ def test_run_model_with_irradiance(sapm_dc_snl_ac_system, location): expected = pd.Series(np.array([187.80746494643176, -0.02]), index=times) - assert_series_equal(ac, expected) + pd.testing.assert_series_equal(ac, expected, atol=1e-5, rtol=1e-5) @pytest.fixture(scope='function') @@ -422,14 +421,12 @@ def test_run_model_from_irradiance_arrays_no_loss( mc_one.run_model(irradiance) mc_two.run_model(irradiance) mc_both.run_model(irradiance) - assert_frame_equal( + pd.testing.assert_frame_equal( mc_both.results.dc[0], - mc_one.results.dc - ) - assert_frame_equal( + mc_one.results.dc, atol=1e-5, rtol=1e-5) + pd.testing.assert_frame_equal( mc_both.results.dc[1], - mc_two.results.dc - ) + mc_two.results.dc, atol=1e-5, rtol=1e-5) @pytest.mark.parametrize("input_type", [tuple, list]) @@ -462,12 +459,10 @@ def test_run_model_from_irradiance_arrays_no_loss_input_type( mc_one.run_model(irradiance) mc_two.run_model(irradiance) mc_both.run_model(input_type((irradiance, irradiance))) - assert_frame_equal( - mc_both.results.dc[0], mc_one.results.dc - ) - assert_frame_equal( - mc_both.results.dc[1], mc_two.results.dc - ) + pd.testing.assert_frame_equal( + mc_both.results.dc[0], mc_one.results.dc, atol=1e-5, rtol=1e-5) + pd.testing.assert_frame_equal( + mc_both.results.dc[1], mc_two.results.dc, atol=1e-5, rtol=1e-5) @pytest.mark.parametrize('inverter', ['adr']) @@ -644,7 +639,7 @@ def test_run_model_perez(sapm_dc_snl_ac_system, location): expected = pd.Series(np.array([187.94295642, -2.00000000e-02]), index=times) - assert_series_equal(ac, expected) + pd.testing.assert_series_equal(ac, expected, atol=1e-5, rtol=1e-5) def test_run_model_gueymard_perez(sapm_dc_snl_ac_system, location): @@ -662,7 +657,7 @@ def test_run_model_gueymard_perez(sapm_dc_snl_ac_system, location): expected = pd.Series(np.array([187.94317405, -2.00000000e-02]), index=times) - assert_series_equal(ac, expected) + pd.testing.assert_series_equal(ac, expected, atol=1e-5, rtol=1e-5) def test_run_model_with_weather_sapm_temp(sapm_dc_snl_ac_system, location, @@ -677,8 +672,16 @@ def test_run_model_with_weather_sapm_temp(sapm_dc_snl_ac_system, location, assert m_sapm.call_count == 1 # assert_called_once_with cannot be used with series, so need to use # assert_series_equal on call_args - assert_series_equal(m_sapm.call_args[0][1], weather['temp_air']) # temp - assert_series_equal(m_sapm.call_args[0][2], weather['wind_speed']) # wind + pd.testing.assert_series_equal( + m_sapm.call_args[0][1], + weather['temp_air'], + atol=1e-5, + rtol=1e-5) # temp + pd.testing.assert_series_equal( + m_sapm.call_args[0][2], + weather['wind_speed'], + atol=1e-5, + rtol=1e-5) # wind assert m_sapm.call_args[1]['model'] == 'sapm' assert not mc.results.ac.empty @@ -696,8 +699,16 @@ def test_run_model_with_weather_pvsyst_temp(sapm_dc_snl_ac_system, location, m_pvsyst = mocker.spy(sapm_dc_snl_ac_system, 'get_cell_temperature') mc.run_model(weather) assert m_pvsyst.call_count == 1 - assert_series_equal(m_pvsyst.call_args[0][1], weather['temp_air']) - assert_series_equal(m_pvsyst.call_args[0][2], weather['wind_speed']) + pd.testing.assert_series_equal( + m_pvsyst.call_args[0][1], + weather['temp_air'], + atol=1e-5, + rtol=1e-5) + pd.testing.assert_series_equal( + m_pvsyst.call_args[0][2], + weather['wind_speed'], + atol=1e-5, + rtol=1e-5) assert m_pvsyst.call_args[1]['model'] == 'pvsyst' assert not mc.results.ac.empty @@ -715,8 +726,16 @@ def test_run_model_with_weather_faiman_temp(sapm_dc_snl_ac_system, location, m_faiman = mocker.spy(sapm_dc_snl_ac_system, 'get_cell_temperature') mc.run_model(weather) assert m_faiman.call_count == 1 - assert_series_equal(m_faiman.call_args[0][1], weather['temp_air']) - assert_series_equal(m_faiman.call_args[0][2], weather['wind_speed']) + pd.testing.assert_series_equal( + m_faiman.call_args[0][1], + weather['temp_air'], + atol=1e-5, + rtol=1e-5) + pd.testing.assert_series_equal( + m_faiman.call_args[0][2], + weather['wind_speed'], + atol=1e-5, + rtol=1e-5) assert m_faiman.call_args[1]['model'] == 'faiman' assert not mc.results.ac.empty @@ -733,8 +752,16 @@ def test_run_model_with_weather_fuentes_temp(sapm_dc_snl_ac_system, location, m_fuentes = mocker.spy(sapm_dc_snl_ac_system, 'get_cell_temperature') mc.run_model(weather) assert m_fuentes.call_count == 1 - assert_series_equal(m_fuentes.call_args[0][1], weather['temp_air']) - assert_series_equal(m_fuentes.call_args[0][2], weather['wind_speed']) + pd.testing.assert_series_equal( + m_fuentes.call_args[0][1], + weather['temp_air'], + atol=1e-5, + rtol=1e-5) + pd.testing.assert_series_equal( + m_fuentes.call_args[0][2], + weather['wind_speed'], + atol=1e-5, + rtol=1e-5) assert m_fuentes.call_args[1]['model'] == 'fuentes' assert not mc.results.ac.empty @@ -751,8 +778,16 @@ def test_run_model_with_weather_noct_sam_temp(sapm_dc_snl_ac_system, location, m_noct_sam = mocker.spy(sapm_dc_snl_ac_system, 'get_cell_temperature') mc.run_model(weather) assert m_noct_sam.call_count == 1 - assert_series_equal(m_noct_sam.call_args[0][1], weather['temp_air']) - assert_series_equal(m_noct_sam.call_args[0][2], weather['wind_speed']) + pd.testing.assert_series_equal( + m_noct_sam.call_args[0][1], + weather['temp_air'], + atol=1e-5, + rtol=1e-5) + pd.testing.assert_series_equal( + m_noct_sam.call_args[0][2], + weather['wind_speed'], + atol=1e-5, + rtol=1e-5) # check that effective_irradiance was used assert m_noct_sam.call_args[1] == { 'effective_irradiance': mc.results.effective_irradiance, @@ -764,7 +799,11 @@ def test__assign_total_irrad(sapm_dc_snl_ac_system, location, weather, data = pd.concat([weather, total_irrad], axis=1) mc = ModelChain(sapm_dc_snl_ac_system, location) mc._assign_total_irrad(data) - assert_frame_equal(mc.results.total_irrad, total_irrad) + pd.testing.assert_frame_equal( + mc.results.total_irrad, + total_irrad, + atol=1e-5, + rtol=1e-5) def test_prepare_inputs_from_poa(sapm_dc_snl_ac_system, location, @@ -779,9 +818,17 @@ def test_prepare_inputs_from_poa(sapm_dc_snl_ac_system, location, weather_expected = weather_expected[ ['ghi', 'dhi', 'dni', 'wind_speed', 'temp_air']] # weather attribute - assert_frame_equal(mc.results.weather, weather_expected) + pd.testing.assert_frame_equal( + mc.results.weather, + weather_expected, + atol=1e-5, + rtol=1e-5) # total_irrad attribute - assert_frame_equal(mc.results.total_irrad, total_irrad) + pd.testing.assert_frame_equal( + mc.results.total_irrad, + total_irrad, + atol=1e-5, + rtol=1e-5) assert not pd.isnull(mc.results.solar_position.index[0]) @@ -845,14 +892,26 @@ def test__prepare_temperature(sapm_dc_snl_ac_system, location, weather, mc._assign_total_irrad(data) mc._prepare_temperature(data) expected = pd.Series([48.928025, 38.080016], index=data.index) - assert_series_equal(mc.results.cell_temperature, expected) + pd.testing.assert_series_equal( + mc.results.cell_temperature, + expected, + atol=1e-5, + rtol=1e-5) data['module_temperature'] = [40., 30.] mc._prepare_temperature(data) expected = pd.Series([42.4, 31.5], index=data.index) - assert_series_equal(mc.results.cell_temperature, expected) + pd.testing.assert_series_equal( + mc.results.cell_temperature, + expected, + atol=1e-5, + rtol=1e-5) data['cell_temperature'] = [50., 35.] mc._prepare_temperature(data) - assert_series_equal(mc.results.cell_temperature, data['cell_temperature']) + pd.testing.assert_series_equal( + mc.results.cell_temperature, + data['cell_temperature'], + atol=1e-5, + rtol=1e-5) def test__prepare_temperature_len1_weather_tuple( @@ -865,7 +924,11 @@ def test__prepare_temperature_len1_weather_tuple( spectral_model='no_loss') mc.run_model([data]) expected = pd.Series([42.617244212941394, 30.0], index=data.index) - assert_series_equal(mc.results.cell_temperature[0], expected) + pd.testing.assert_series_equal( + mc.results.cell_temperature[0], + expected, + atol=1e-5, + rtol=1e-5) data = weather.copy().rename( columns={ @@ -875,7 +938,11 @@ def test__prepare_temperature_len1_weather_tuple( spectral_model='no_loss') mc.run_model_from_poa([data]) expected = pd.Series([41.5, 30.0], index=data.index) - assert_series_equal(mc.results.cell_temperature[0], expected) + pd.testing.assert_series_equal( + mc.results.cell_temperature[0], + expected, + atol=1e-5, + rtol=1e-5) data = weather.copy()[["module_temperature", "ghi"]].rename( columns={"ghi": "effective_irradiance"} @@ -884,7 +951,11 @@ def test__prepare_temperature_len1_weather_tuple( spectral_model='no_loss') mc.run_model_from_effective_irradiance([data]) expected = pd.Series([41.5, 30.0], index=data.index) - assert_series_equal(mc.results.cell_temperature[0], expected) + pd.testing.assert_series_equal( + mc.results.cell_temperature[0], + expected, + atol=1e-5, + rtol=1e-5) def test__prepare_temperature_arrays_weather(sapm_dc_snl_ac_system_same_arrays, @@ -901,28 +972,56 @@ def test__prepare_temperature_arrays_weather(sapm_dc_snl_ac_system_same_arrays, mc._assign_total_irrad((data, data_two)) mc._prepare_temperature((data, data_two)) expected = pd.Series([48.928025, 38.080016], index=data.index) - assert_series_equal(mc.results.cell_temperature[0], expected) - assert_series_equal(mc.results.cell_temperature[1], expected) + pd.testing.assert_series_equal( + mc.results.cell_temperature[0], + expected, + atol=1e-5, + rtol=1e-5) + pd.testing.assert_series_equal( + mc.results.cell_temperature[1], + expected, + atol=1e-5, + rtol=1e-5) data['module_temperature'] = [40., 30.] mc._prepare_temperature((data, data_two)) expected = pd.Series([42.4, 31.5], index=data.index) assert (mc.results.cell_temperature[1] != expected).all() - assert_series_equal(mc.results.cell_temperature[0], expected) + pd.testing.assert_series_equal( + mc.results.cell_temperature[0], + expected, + atol=1e-5, + rtol=1e-5) data['cell_temperature'] = [50., 35.] mc._prepare_temperature((data, data_two)) - assert_series_equal( - mc.results.cell_temperature[0], data['cell_temperature']) + pd.testing.assert_series_equal( + mc.results.cell_temperature[0], + data['cell_temperature'], + atol=1e-5, + rtol=1e-5) data_two['module_temperature'] = [40., 30.] mc._prepare_temperature((data, data_two)) - assert_series_equal(mc.results.cell_temperature[1], expected) - assert_series_equal( - mc.results.cell_temperature[0], data['cell_temperature']) + pd.testing.assert_series_equal( + mc.results.cell_temperature[1], + expected, + atol=1e-5, + rtol=1e-5) + pd.testing.assert_series_equal( + mc.results.cell_temperature[0], + data['cell_temperature'], + atol=1e-5, + rtol=1e-5) data_two['cell_temperature'] = [10.0, 20.0] mc._prepare_temperature((data, data_two)) - assert_series_equal( - mc.results.cell_temperature[1], data_two['cell_temperature']) - assert_series_equal( - mc.results.cell_temperature[0], data['cell_temperature']) + pd.testing.assert_series_equal( + mc.results.cell_temperature[1], + data_two['cell_temperature'], + atol=1e-5, + rtol=1e-5) + pd.testing.assert_series_equal( + mc.results.cell_temperature[0], + data['cell_temperature'], + atol=1e-5, + rtol=1e-5) @pytest.mark.parametrize('temp_params,temp_model', @@ -964,8 +1063,16 @@ def test_run_model_solar_position_weather( mc.run_model(weather) # assert_called_once_with cannot be used with series, so need to use # assert_series_equal on call_args - assert_series_equal(m.call_args[1]['temperature'], weather['temp_air']) - assert_series_equal(m.call_args[1]['pressure'], weather['pressure']) + pd.testing.assert_series_equal( + m.call_args[1]['temperature'], + weather['temp_air'], + atol=1e-5, + rtol=1e-5) + pd.testing.assert_series_equal( + m.call_args[1]['pressure'], + weather['pressure'], + atol=1e-5, + rtol=1e-5) def test_run_model_from_poa(sapm_dc_snl_ac_system, location, total_irrad): @@ -974,7 +1081,7 @@ def test_run_model_from_poa(sapm_dc_snl_ac_system, location, total_irrad): ac = mc.run_model_from_poa(total_irrad).results.ac expected = pd.Series(np.array([149.280238, 96.678385]), index=total_irrad.index) - assert_series_equal(ac, expected) + pd.testing.assert_series_equal(ac, expected, atol=1e-5, rtol=1e-5) @pytest.mark.parametrize("input_type", [tuple, list]) @@ -988,7 +1095,11 @@ def test_run_model_from_poa_arrays(sapm_dc_snl_ac_system_Array, location, # arrays have different orientation, but should give same dc power # because we are the same passing POA irradiance and air # temperature. - assert_frame_equal(mc.results.dc[0], mc.results.dc[1]) + pd.testing.assert_frame_equal( + mc.results.dc[0], + mc.results.dc[1], + atol=1e-5, + rtol=1e-5) def test_run_model_from_poa_arrays_solar_position_weather( @@ -1005,8 +1116,16 @@ def test_run_model_from_poa_arrays_solar_position_weather( m = mocker.spy(location, 'get_solarposition') mc.run_model_from_poa((data, data2)) # mc uses only the first weather data for solar position corrections - assert_series_equal(m.call_args[1]['temperature'], data['temp_air']) - assert_series_equal(m.call_args[1]['pressure'], data['pressure']) + pd.testing.assert_series_equal( + m.call_args[1]['temperature'], + data['temp_air'], + atol=1e-5, + rtol=1e-5) + pd.testing.assert_series_equal( + m.call_args[1]['pressure'], + data['pressure'], + atol=1e-5, + rtol=1e-5) @pytest.mark.parametrize("input_type", [lambda x: x[0], tuple, list]) @@ -1020,7 +1139,7 @@ def test_run_model_from_effective_irradiance(sapm_dc_snl_ac_system, location, ac = mc.run_model_from_effective_irradiance(input_type((data,))).results.ac expected = pd.Series(np.array([149.280238, 96.678385]), index=data.index) - assert_series_equal(ac, expected) + pd.testing.assert_series_equal(ac, expected, atol=1e-5, rtol=1e-5) @pytest.mark.parametrize("input_type", [tuple, list]) @@ -1036,7 +1155,11 @@ def test_run_model_from_effective_irradiance_multi_array( # arrays have different orientation, but should give same dc power # because we are the same passing POA irradiance and air # temperature. - assert_frame_equal(mc.results.dc[0], mc.results.dc[1]) + pd.testing.assert_frame_equal( + mc.results.dc[0], + mc.results.dc[1], + atol=1e-5, + rtol=1e-5) @pytest.mark.parametrize("input_type", [lambda x: x[0], tuple, list]) @@ -1049,7 +1172,7 @@ def test_run_model_from_effective_irradiance_no_poa_global( ac = mc.run_model_from_effective_irradiance(input_type((data,))).results.ac expected = pd.Series(np.array([149.280238, 96.678385]), index=data.index) - assert_series_equal(ac, expected) + pd.testing.assert_series_equal(ac, expected, atol=1e-5, rtol=1e-5) def test_run_model_from_effective_irradiance_poa_global_differs( @@ -1062,7 +1185,7 @@ def test_run_model_from_effective_irradiance_poa_global_differs( ac = mc.run_model_from_effective_irradiance(data).results.ac expected = pd.Series(np.array([118.302801, 76.099841]), index=data.index) - assert_series_equal(ac, expected) + pd.testing.assert_series_equal(ac, expected, atol=1e-5, rtol=1e-5) @pytest.mark.parametrize("input_type", [tuple, list]) @@ -1102,7 +1225,11 @@ def test_run_model_from_effective_irradiance_arrays( # arrays have different orientation, but should give same dc power # because we are the same passing effective irradiance and cell # temperature. - assert_frame_equal(mc.results.dc[0], mc.results.dc[1]) + pd.testing.assert_frame_equal( + mc.results.dc[0], + mc.results.dc[1], + atol=1e-5, + rtol=1e-5) # test that unequal inputs create unequal results data_two = data.copy() data_two['effective_irradiance'] = data['poa_global'] * 0.5 @@ -1119,13 +1246,21 @@ def test_run_model_from_effective_irradiance_minimal_input( mc = ModelChain(sapm_dc_snl_ac_system, location) mc.run_model_from_effective_irradiance(data) # make sure, for a single Array, the result is the correct type and value - assert_series_equal(mc.results.cell_temperature, data['cell_temperature']) + pd.testing.assert_series_equal( + mc.results.cell_temperature, + data['cell_temperature'], + atol=1e-5, + rtol=1e-5) assert not mc.results.dc.empty assert not mc.results.ac.empty # test with multiple arrays mc = ModelChain(sapm_dc_snl_ac_system_Array, location) mc.run_model_from_effective_irradiance((data, data)) - assert_frame_equal(mc.results.dc[0], mc.results.dc[1]) + pd.testing.assert_frame_equal( + mc.results.dc[0], + mc.results.dc[1], + atol=1e-5, + rtol=1e-5) assert not mc.results.ac.empty @@ -1157,7 +1292,7 @@ def test_run_model_from_poa_singleton_weather_single_array( assert isinstance(mc.results.cell_temperature, tuple) assert len(mc.results.cell_temperature) == 1 assert isinstance(mc.results.cell_temperature[0], pd.Series) - assert_series_equal(ac, expected) + pd.testing.assert_series_equal(ac, expected, atol=1e-5, rtol=1e-5) def test_run_model_from_effective_irradiance_weather_single_array( @@ -1177,7 +1312,7 @@ def test_run_model_from_effective_irradiance_weather_single_array( assert isinstance(mc.results.dc, tuple) assert len(mc.results.dc) == 1 assert isinstance(mc.results.dc[0], pd.DataFrame) - assert_series_equal(ac, expected) + pd.testing.assert_series_equal(ac, expected, atol=1e-5, rtol=1e-5) def poadc(mc): @@ -1357,7 +1492,11 @@ def test_pvwatts_dc_multiple_strings(pvwatts_dc_pvwatts_ac_system, location, assert not mc2.results.ac.empty expected = pd.Series(data=[2., np.nan], index=mc2.results.dc.index, name='p_mp') - assert_series_equal(mc2.results.dc / mc1.results.dc, expected) + pd.testing.assert_series_equal( + mc2.results.dc / mc1.results.dc, + expected, + atol=1e-5, + rtol=1e-5) def acdc(mc): @@ -1419,7 +1558,11 @@ def test_ac_model_user_func(pvwatts_dc_pvwatts_ac_system, location, weather, aoi_model='no_loss', spectral_model='no_loss') mc.run_model(weather) assert m.call_count == 1 - assert_series_equal(mc.results.ac, mc.results.dc) + pd.testing.assert_series_equal( + mc.results.ac, + mc.results.dc, + atol=1e-5, + rtol=1e-5) assert not mc.results.ac.empty @@ -1850,12 +1993,21 @@ def test_complete_irradiance_clean_run(sapm_dc_snl_ac_system, location): mc.complete_irradiance(i) - assert_series_equal(mc.results.weather['dni'], - pd.Series([2, 3], index=times, name='dni')) - assert_series_equal(mc.results.weather['dhi'], - pd.Series([4, 6], index=times, name='dhi')) - assert_series_equal(mc.results.weather['ghi'], - pd.Series([9, 5], index=times, name='ghi')) + pd.testing.assert_series_equal( + mc.results.weather['dni'], + pd.Series([2, 3], index=times, name='dni'), + atol=1e-5, + rtol=1e-5) + pd.testing.assert_series_equal( + mc.results.weather['dhi'], + pd.Series([4, 6], index=times, name='dhi'), + atol=1e-5, + rtol=1e-5) + pd.testing.assert_series_equal( + mc.results.weather['ghi'], + pd.Series([9, 5], index=times, name='ghi'), + atol=1e-5, + rtol=1e-5) def test_complete_irradiance(sapm_dc_snl_ac_system, location, mocker): @@ -1868,24 +2020,30 @@ def test_complete_irradiance(sapm_dc_snl_ac_system, location, mocker): with pytest.warns(UserWarning): mc.complete_irradiance(i[['ghi', 'dni']]) - assert_series_equal(mc.results.weather['dhi'], - pd.Series([356.543700, 465.44400], - index=times, name='dhi')) + pd.testing.assert_series_equal( + mc.results.weather['dhi'], + pd.Series([356.543700, 465.44400], index=times, name='dhi'), + atol=1e-5, + rtol=1e-5) with pytest.warns(UserWarning): mc.complete_irradiance(i[['dhi', 'dni']]) - assert_series_equal(mc.results.weather['ghi'], - pd.Series([372.103976116, 497.087579068], - index=times, name='ghi')) + pd.testing.assert_series_equal( + mc.results.weather['ghi'], + pd.Series([372.103976116, 497.087579068], index=times, name='ghi'), + atol=1e-5, + rtol=1e-5) # check that clearsky_model is used correctly m_ineichen = mocker.spy(location, 'get_clearsky') mc.complete_irradiance(i[['dhi', 'ghi']]) assert m_ineichen.call_count == 1 assert m_ineichen.call_args[1]['model'] == 'ineichen' - assert_series_equal(mc.results.weather['dni'], - pd.Series([49.756966, 62.153947], - index=times, name='dni')) + pd.testing.assert_series_equal( + mc.results.weather['dni'], + pd.Series([49.756966, 62.153947], index=times, name='dni'), + atol=1e-5, + rtol=1e-5) @pytest.mark.filterwarnings("ignore:This function is not safe at the moment") @@ -1904,24 +2062,42 @@ def test_complete_irradiance_arrays( mc.complete_irradiance(input_type((weather, weather[1:]))) mc.complete_irradiance(input_type((weather, weather))) for mc_weather in mc.results.weather: - assert_series_equal(mc_weather['dni'], - pd.Series([2, 3], index=times, name='dni')) - assert_series_equal(mc_weather['dhi'], - pd.Series([4, 6], index=times, name='dhi')) - assert_series_equal(mc_weather['ghi'], - pd.Series([9, 5], index=times, name='ghi')) + pd.testing.assert_series_equal( + mc_weather['dni'], + pd.Series([2, 3], index=times, name='dni'), + atol=1e-5, + rtol=1e-5) + pd.testing.assert_series_equal( + mc_weather['dhi'], + pd.Series([4, 6], index=times, name='dhi'), + atol=1e-5, + rtol=1e-5) + pd.testing.assert_series_equal( + mc_weather['ghi'], + pd.Series([9, 5], index=times, name='ghi'), + atol=1e-5, + rtol=1e-5) mc = ModelChain(sapm_dc_snl_ac_system_same_arrays, location) mc.complete_irradiance(input_type((weather[['ghi', 'dhi']], weather[['dhi', 'dni']]))) assert 'dni' in mc.results.weather[0].columns assert 'ghi' in mc.results.weather[1].columns mc.complete_irradiance(input_type((weather, weather[['ghi', 'dni']]))) - assert_series_equal(mc.results.weather[0]['dhi'], - pd.Series([4, 6], index=times, name='dhi')) - assert_series_equal(mc.results.weather[0]['ghi'], - pd.Series([9, 5], index=times, name='ghi')) - assert_series_equal(mc.results.weather[0]['dni'], - pd.Series([2, 3], index=times, name='dni')) + pd.testing.assert_series_equal( + mc.results.weather[0]['dhi'], + pd.Series([4, 6], index=times, name='dhi'), + atol=1e-5, + rtol=1e-5) + pd.testing.assert_series_equal( + mc.results.weather[0]['ghi'], + pd.Series([9, 5], index=times, name='ghi'), + atol=1e-5, + rtol=1e-5) + pd.testing.assert_series_equal( + mc.results.weather[0]['dni'], + pd.Series([2, 3], index=times, name='dni'), + atol=1e-5, + rtol=1e-5) assert 'dhi' in mc.results.weather[1].columns @@ -2026,20 +2202,32 @@ def test__irrad_for_celltemp(): effect_irrad = pd.Series(index=total_irrad.index, data=[5., 8.]) # test with single array inputs poa = modelchain._irrad_for_celltemp(total_irrad, effect_irrad) - assert_series_equal(poa, total_irrad['poa_global']) + pd.testing.assert_series_equal( + poa, + total_irrad['poa_global'], + atol=1e-5, + rtol=1e-5) poa = modelchain._irrad_for_celltemp(empty, effect_irrad) - assert_series_equal(poa, effect_irrad) + pd.testing.assert_series_equal(poa, effect_irrad, atol=1e-5, rtol=1e-5) # test with tuples poa = modelchain._irrad_for_celltemp( (total_irrad, total_irrad), (effect_irrad, effect_irrad)) assert len(poa) == 2 - assert_series_equal(poa[0], total_irrad['poa_global']) - assert_series_equal(poa[1], total_irrad['poa_global']) + pd.testing.assert_series_equal( + poa[0], + total_irrad['poa_global'], + atol=1e-5, + rtol=1e-5) + pd.testing.assert_series_equal( + poa[1], + total_irrad['poa_global'], + atol=1e-5, + rtol=1e-5) poa = modelchain._irrad_for_celltemp( (empty, empty), (effect_irrad, effect_irrad)) assert len(poa) == 2 - assert_series_equal(poa[0], effect_irrad) - assert_series_equal(poa[1], effect_irrad) + pd.testing.assert_series_equal(poa[0], effect_irrad, atol=1e-5, rtol=1e-5) + pd.testing.assert_series_equal(poa[1], effect_irrad, atol=1e-5, rtol=1e-5) def test_ModelChain___repr__(sapm_dc_snl_ac_system, location): diff --git a/tests/test_pvarray.py b/tests/test_pvarray.py index e614f885db..3c33f61e28 100644 --- a/tests/test_pvarray.py +++ b/tests/test_pvarray.py @@ -2,7 +2,6 @@ from numpy import nan import pandas as pd from numpy.testing import assert_allclose -from .conftest import assert_series_equal import pytest from pvlib import pvarray @@ -68,7 +67,7 @@ def test_huld(): tm = pd.Series([25, 30, 30]) expected = pd.Series([pdc0, exp_100, 0]) res = pvarray.huld(eff_irr, tm, pdc0, k=(1, 1, 1, 1, 1, 1)) - assert_series_equal(res, expected) + pd.testing.assert_series_equal(res, expected, atol=1e-5, rtol=1e-5) with pytest.raises(ValueError, match='Either k or cell_type must be specified' ): diff --git a/tests/test_pvsystem.py b/tests/test_pvsystem.py index 71a515ab03..79e9ead4b1 100644 --- a/tests/test_pvsystem.py +++ b/tests/test_pvsystem.py @@ -5,7 +5,6 @@ import pandas as pd import pytest -from .conftest import assert_series_equal, assert_frame_equal from numpy.testing import assert_allclose import unittest.mock as mock @@ -256,7 +255,7 @@ def test_sapm(sapm_module_params): columns=['i_sc', 'i_mp', 'v_oc', 'v_mp', 'p_mp', 'i_x', 'i_xx'], index=times) - assert_frame_equal(out, expected, check_less_precise=4) + pd.testing.assert_frame_equal(out, expected, atol=1e-3, rtol=1e-3) out = pvsystem.sapm(1000, 25, sapm_module_params) @@ -400,7 +399,7 @@ def test_sapm_effective_irradiance(sapm_module_params, test_input, expected): test_input.append(sapm_module_params) out = pvsystem.sapm_effective_irradiance(*test_input) if isinstance(test_input, pd.Series): - assert_series_equal(out, expected, check_less_precise=4) + pd.testing.assert_series_equal(out, expected, atol=1e-3, rtol=1e-3) else: assert_allclose(out, expected, atol=1e-1) @@ -634,7 +633,11 @@ def test_PVSystem_noct_celltemp(mocker): pd.Series(index=dr, data=temp_air), pd.Series(index=dr, data=wind_speed), model='noct_sam') - assert_series_equal(out, pd.Series(index=dr, data=expected)) + pd.testing.assert_series_equal( + out, + pd.Series(index=dr, data=expected), + atol=1e-5, + rtol=1e-5) # now use optional arguments temp_model_params.update({'transmittance_absorptance': 0.8, 'array_height': 2, @@ -691,8 +694,16 @@ def test_PVSystem_multi_array_celltemp_multi_temp(model, two_array_system): wind_speed, model=model ) - assert_series_equal(temp_one, temp_two_switch) - assert_series_equal(temp_two, temp_one_swtich) + pd.testing.assert_series_equal( + temp_one, + temp_two_switch, + atol=1e-5, + rtol=1e-5) + pd.testing.assert_series_equal( + temp_two, + temp_one_swtich, + atol=1e-5, + rtol=1e-5) @pytest.mark.parametrize("model", @@ -716,8 +727,16 @@ def test_PVSystem_multi_array_celltemp_multi_wind(model, two_array_system): (wind_speed_two, wind_speed_one), model=model ) - assert_series_equal(temp_one, temp_two_switch) - assert_series_equal(temp_two, temp_one_swtich) + pd.testing.assert_series_equal( + temp_one, + temp_two_switch, + atol=1e-5, + rtol=1e-5) + pd.testing.assert_series_equal( + temp_two, + temp_one_swtich, + atol=1e-5, + rtol=1e-5) def test_PVSystem_get_cell_temperature_invalid(): @@ -785,12 +804,27 @@ def test_PVSystem_fuentes_celltemp(mocker): irrads = pd.Series(1000, index) winds = pd.Series(1, index) out = system.get_cell_temperature(irrads, temps, winds, model='fuentes') - assert_series_equal(spy.call_args[0][0], irrads) - assert_series_equal(spy.call_args[0][1], temps) - assert_series_equal(spy.call_args[0][2], winds) + pd.testing.assert_series_equal( + spy.call_args[0][0], + irrads, + atol=1e-5, + rtol=1e-5) + pd.testing.assert_series_equal( + spy.call_args[0][1], + temps, + atol=1e-5, + rtol=1e-5) + pd.testing.assert_series_equal( + spy.call_args[0][2], + winds, + atol=1e-5, + rtol=1e-5) assert spy.call_args[0][3] == noct_installed - assert_series_equal(out, pd.Series([52.884, 56.835, 56.836], index, - name='tmod')) + pd.testing.assert_series_equal( + out, + pd.Series([52.884, 56.835, 56.836], index, name='tmod'), + atol=1e-5, + rtol=1e-5) def test_PVSystem_fuentes_module_height(mocker): @@ -1052,16 +1086,31 @@ def test_calcparams_desoto(cec_module_params): dEgdT=-0.0002677 ) - assert_series_equal(IL, pd.Series([0.0, 6.036, 6.096], index=times), - check_less_precise=3) - assert_series_equal(I0, pd.Series([0.0, 1.94e-9, 7.419e-8], index=times), - check_less_precise=3) - assert_series_equal(Rs, pd.Series([0.094, 0.094, 0.094], index=times), - check_less_precise=3) - assert_series_equal(Rsh, pd.Series([np.inf, 19.65, 19.65], index=times), - check_less_precise=3) - assert_series_equal(nNsVth, pd.Series([0.473, 0.473, 0.5127], index=times), - check_less_precise=3) + pd.testing.assert_series_equal( + IL, + pd.Series([0.0, 6.036, 6.096], index=times), + atol=1e-3, + rtol=1e-3) + pd.testing.assert_series_equal( + I0, + pd.Series([0.0, 1.94e-9, 7.419e-8], index=times), + atol=1e-3, + rtol=1e-3) + pd.testing.assert_series_equal( + Rs, + pd.Series([0.094, 0.094, 0.094], index=times), + atol=1e-3, + rtol=1e-3) + pd.testing.assert_series_equal( + Rsh, + pd.Series([np.inf, 19.65, 19.65], index=times), + atol=1e-3, + rtol=1e-3) + pd.testing.assert_series_equal( + nNsVth, + pd.Series([0.473, 0.473, 0.5127], index=times), + atol=1e-3, + rtol=1e-3) def test_calcparams_cec(cec_module_params): @@ -1085,16 +1134,31 @@ def test_calcparams_cec(cec_module_params): dEgdT=-0.0002677 ) - assert_series_equal(IL, pd.Series([0.0, 6.036, 6.0896], index=times), - check_less_precise=3) - assert_series_equal(I0, pd.Series([0.0, 1.94e-9, 7.419e-8], index=times), - check_less_precise=3) - assert_series_equal(Rs, pd.Series([0.094, 0.094, 0.094], index=times), - check_less_precise=3) - assert_series_equal(Rsh, pd.Series([np.inf, 19.65, 19.65], index=times), - check_less_precise=3) - assert_series_equal(nNsVth, pd.Series([0.473, 0.473, 0.5127], index=times), - check_less_precise=3) + pd.testing.assert_series_equal( + IL, + pd.Series([0.0, 6.036, 6.0896], index=times), + atol=1e-3, + rtol=1e-3) + pd.testing.assert_series_equal( + I0, + pd.Series([0.0, 1.94e-9, 7.419e-8], index=times), + atol=1e-3, + rtol=1e-3) + pd.testing.assert_series_equal( + Rs, + pd.Series([0.094, 0.094, 0.094], index=times), + atol=1e-3, + rtol=1e-3) + pd.testing.assert_series_equal( + Rsh, + pd.Series([np.inf, 19.65, 19.65], index=times), + atol=1e-3, + rtol=1e-3) + pd.testing.assert_series_equal( + nNsVth, + pd.Series([0.473, 0.473, 0.5127], index=times), + atol=1e-3, + rtol=1e-3) def test_calcparams_cec_extra_params_propagation(cec_module_params, mocker): @@ -1155,16 +1219,31 @@ def test_calcparams_pvsyst(pvsyst_module_params): cells_in_series=pvsyst_module_params['cells_in_series'], EgRef=pvsyst_module_params['EgRef']) - assert_series_equal( - IL.round(decimals=3), pd.Series([0.0, 4.8200], index=times)) - assert_series_equal( - I0.round(decimals=3), pd.Series([0.0, 1.47e-7], index=times)) - assert_series_equal( - Rs.round(decimals=3), pd.Series([0.500, 0.500], index=times)) - assert_series_equal( - Rsh.round(decimals=3), pd.Series([1000.0, 305.757], index=times)) - assert_series_equal( - nNsVth.round(decimals=4), pd.Series([1.6186, 1.7961], index=times)) + pd.testing.assert_series_equal( + IL.round(decimals=3), + pd.Series([0.0, 4.8200], index=times), + atol=1e-5, + rtol=1e-5) + pd.testing.assert_series_equal( + I0.round(decimals=3), + pd.Series([0.0, 1.47e-7], index=times), + atol=1e-5, + rtol=1e-5) + pd.testing.assert_series_equal( + Rs.round(decimals=3), + pd.Series([0.500, 0.500], index=times), + atol=1e-5, + rtol=1e-5) + pd.testing.assert_series_equal( + Rsh.round(decimals=3), + pd.Series([1000.0, 305.757], index=times), + atol=1e-5, + rtol=1e-5) + pd.testing.assert_series_equal( + nNsVth.round(decimals=4), + pd.Series([1.6186, 1.7961], index=times), + atol=1e-5, + rtol=1e-5) def test_PVSystem_calcparams_desoto(cec_module_params, mocker): @@ -1754,7 +1833,7 @@ def test_scale_voltage_current_power(): columns=['i_sc', 'i_mp', 'v_oc', 'v_mp', 'p_mp', 'i_x', 'i_xx'], index=[0]) out = pvsystem.scale_voltage_current_power(data, voltage=2, current=3) - assert_frame_equal(out, expected, check_less_precise=5) + pd.testing.assert_frame_equal(out, expected, atol=1e-3, rtol=1e-3) def test_PVSystem_scale_voltage_current_power(mocker): @@ -1799,7 +1878,11 @@ def test_PVSystem_get_ac_sandia(cec_inverter_parameters, mocker): pdcs = idcs * vdcs pacs = system.get_ac('sandia', pdcs, v_dc=vdcs) inv_fun.assert_called_once() - assert_series_equal(pacs, pd.Series([-0.020000, 132.004308, 250.000000])) + pd.testing.assert_series_equal( + pacs, + pd.Series([-0.020000, 132.004308, 250.000000]), + atol=1e-5, + rtol=1e-5) def test_PVSystem_get_ac_sandia_multi(cec_inverter_parameters, mocker): @@ -1815,7 +1898,11 @@ def test_PVSystem_get_ac_sandia_multi(cec_inverter_parameters, mocker): pdcs = idcs * vdcs pacs = system.get_ac('sandia', (pdcs, pdcs), v_dc=(vdcs, vdcs)) inv_fun.assert_called_once() - assert_series_equal(pacs, pd.Series([-0.020000, 132.004308, 250.000000])) + pd.testing.assert_series_equal( + pacs, + pd.Series([-0.020000, 132.004308, 250.000000]), + atol=1e-5, + rtol=1e-5) with pytest.raises(ValueError, match="Length mismatch for per-array parameter"): system.get_ac('sandia', vdcs, (pdcs, pdcs)) @@ -1859,7 +1946,7 @@ def test_PVSystem_get_ac_pvwatts_multi( ) pdcs = pd.Series([0., 25., 50.]) pacs = system.get_ac('pvwatts', (pdcs, pdcs)) - assert_series_equal(pacs, exp) + pd.testing.assert_series_equal(pacs, exp, atol=1e-5, rtol=1e-5) assert inverter.pvwatts_multi.call_count == 2 with pytest.raises(ValueError, match="Length mismatch for per-array parameter"): @@ -1903,7 +1990,11 @@ def test_PVSystem_get_ac_single_array_tuple_input( if model == 'pvwatts': assert ac < pdcs['pvwatts'] else: - assert_series_equal(ac, expected[model]) + pd.testing.assert_series_equal( + ac, + expected[model], + atol=1e-5, + rtol=1e-5) def test_PVSystem_get_ac_adr(adr_inverter_parameters, mocker): @@ -1914,8 +2005,11 @@ def test_PVSystem_get_ac_adr(adr_inverter_parameters, mocker): vdcs = pd.Series([135, 154, 390, 420, 551]) pdcs = pd.Series([135, 1232, 1170, 420, 551]) pacs = system.get_ac('adr', pdcs, vdcs) - assert_series_equal(pacs, pd.Series([np.nan, 1161.5745, 1116.4459, - 382.6679, np.nan])) + pd.testing.assert_series_equal( + pacs, + pd.Series([np.nan, 1161.5745, 1116.4459, 382.6679, np.nan]), + atol=1e-5, + rtol=1e-5) inverter.adr.assert_called_once_with(vdcs, pdcs, system.inverter_parameters) @@ -2001,7 +2095,7 @@ def test_PVSystem_get_irradiance(solar_pos): 'poa_diffuse', 'poa_sky_diffuse', 'poa_ground_diffuse'], index=solar_pos.index) - assert_frame_equal(irradiance, expected, check_less_precise=2) + pd.testing.assert_frame_equal(irradiance, expected, atol=1e-3, rtol=1e-3) def test_PVSystem_get_irradiance_float(): @@ -2039,7 +2133,7 @@ def test_PVSystem_get_irradiance_albedo(solar_pos): columns=['poa_global', 'poa_direct', 'poa_diffuse', 'poa_sky_diffuse', 'poa_ground_diffuse'], index=solar_pos.index) - assert_frame_equal(irradiance, expected, check_less_precise=2) + pd.testing.assert_frame_equal(irradiance, expected, atol=1e-3, rtol=1e-3) def test_PVSystem_get_irradiance_model(mocker, solar_pos): @@ -2087,12 +2181,10 @@ def test_PVSystem_multi_array_get_irradiance(solar_pos): solar_pos['azimuth'], irrads['dni'], irrads['ghi'], irrads['dhi'] ) - assert_frame_equal( - array_one_irrad, array_one_expected, check_less_precise=2 - ) - assert_frame_equal( - array_two_irrad, array_two_expected, check_less_precise=2 - ) + pd.testing.assert_frame_equal( + array_one_irrad, array_one_expected, atol=1e-3, rtol=1e-3) + pd.testing.assert_frame_equal( + array_two_irrad, array_two_expected, atol=1e-3, rtol=1e-3) def test_PVSystem_multi_array_get_irradiance_multi_irrad(solar_pos): @@ -2120,7 +2212,11 @@ def test_PVSystem_multi_array_get_irradiance_multi_irrad(solar_pos): (irrads['ghi'], irrads['ghi']), (irrads['dni'], irrads['dni']) ) - assert_frame_equal(array_irrad[0], array_irrad[1]) + pd.testing.assert_frame_equal( + array_irrad[0], + array_irrad[1], + atol=1e-5, + rtol=1e-5) array_irrad = system.get_irradiance( solar_pos['apparent_zenith'], solar_pos['azimuth'], @@ -2139,8 +2235,16 @@ def test_PVSystem_multi_array_get_irradiance_multi_irrad(solar_pos): irrads_two['dhi'], irrads_two['ghi'], irrads_two['dni'] ) assert not array_irrad[0].equals(array_irrad[1]) - assert_frame_equal(array_irrad[0], array_one_expected) - assert_frame_equal(array_irrad[1], array_two_expected) + pd.testing.assert_frame_equal( + array_irrad[0], + array_one_expected, + atol=1e-5, + rtol=1e-5) + pd.testing.assert_frame_equal( + array_irrad[1], + array_two_expected, + atol=1e-5, + rtol=1e-5) with pytest.raises(ValueError, match="Length mismatch for per-array parameter"): system.get_irradiance( @@ -2157,7 +2261,11 @@ def test_PVSystem_multi_array_get_irradiance_multi_irrad(solar_pos): irrads['ghi'], irrads['dni'] ) - assert_frame_equal(array_irrad[0], array_one_expected) + pd.testing.assert_frame_equal( + array_irrad[0], + array_one_expected, + atol=1e-5, + rtol=1e-5) assert not array_irrad[0].equals(array_irrad[1]) @@ -2181,7 +2289,7 @@ def test_Array_get_irradiance(solar_pos): 'poa_ground_diffuse'], index=solar_pos.index ) - assert_frame_equal(modeled, expected, check_less_precise=5) + pd.testing.assert_frame_equal(modeled, expected, atol=1e-3, rtol=1e-3) # with specified kwargs, use isotropic sky diffuse because it's easier modeled = array.get_irradiance( solar_pos['apparent_zenith'], @@ -2196,7 +2304,7 @@ def test_Array_get_irradiance(solar_pos): solar_pos['apparent_zenith'], solar_pos['azimuth']) direct = irrads['dni'] * cosd(aoi) expected = sky_diffuse + ground_diff + direct - assert_series_equal(expected, expected, check_less_precise=5) + pd.testing.assert_series_equal(expected, expected, atol=1e-3, rtol=1e-3) def test_PVSystem___repr__(): @@ -2297,7 +2405,7 @@ def test_pvwatts_dc_series(): temp_cell = pd.Series([30, np.nan, 30]) expected = pd.Series(np.array([ nan, nan, 88.65])) out = pvsystem.pvwatts_dc(irrad_trans, temp_cell, 100, -0.003) - assert_series_equal(expected, out) + pd.testing.assert_series_equal(expected, out, atol=1e-5, rtol=1e-5) def test_pvwatts_dc_scalars_with_k(): @@ -2322,7 +2430,7 @@ def test_pvwatts_dc_series_with_k(): temp_cell = pd.Series([30, np.nan, 30, 30]) expected = pd.Series(np.array([ nan, nan, 8.9125, 118.45])) out = pvsystem.pvwatts_dc(irrad_trans, temp_cell, 100, -0.003, k=0.01) - assert_series_equal(expected, out) + pd.testing.assert_series_equal(expected, out, atol=1e-5, rtol=1e-5) def test_pvwatts_dc_with_k_and_cap_adjustment(): @@ -2365,7 +2473,7 @@ def test_pvwatts_losses_series(): expected = pd.Series([nan, 14.934904]) age = pd.Series([nan, 1]) out = pvsystem.pvwatts_losses(age=age) - assert_series_equal(expected, out) + pd.testing.assert_series_equal(expected, out, atol=1e-5, rtol=1e-5) @pytest.fixture @@ -2510,7 +2618,7 @@ def test_combine_loss_factors(): periods=12, freq='MS')) expected = pd.Series(.1621, index=test_index) out = pvsystem.combine_loss_factors(test_index, loss_1, loss_2, loss_3) - assert_series_equal(expected, out) + pd.testing.assert_series_equal(expected, out, atol=1e-5, rtol=1e-5) def test_no_extra_kwargs(): diff --git a/tests/test_snow.py b/tests/test_snow.py index d12a92586e..c72758497f 100644 --- a/tests/test_snow.py +++ b/tests/test_snow.py @@ -1,7 +1,6 @@ import numpy as np import pandas as pd -from .conftest import assert_series_equal from pvlib import snow from pvlib.tools import sind @@ -16,7 +15,11 @@ def test_fully_covered_nrel(): expected = pd.Series([False, True, False, True, False, False, True], index=dt) fully_covered = snow.fully_covered_nrel(snowfall_data) - assert_series_equal(expected, fully_covered) + pd.testing.assert_series_equal( + expected, + fully_covered, + atol=1e-5, + rtol=1e-5) def test_fully_covered_nrel_with_snow_depth(): @@ -29,7 +32,11 @@ def test_fully_covered_nrel_with_snow_depth(): fully_covered = snow.fully_covered_nrel(snowfall_data, snow_depth=snow_depth, threshold_depth=0.) - assert_series_equal(expected, fully_covered) + pd.testing.assert_series_equal( + expected, + fully_covered, + atol=1e-5, + rtol=1e-5) def test_coverage_nrel_hourly(): @@ -48,7 +55,11 @@ def test_coverage_nrel_hourly(): slide_amt = slide_amount_coefficient * sind(surface_tilt) covered = 1.0 - slide_amt * np.array([0, 1, 2, 3, 4, 5, 6, 7]) expected = pd.Series(covered, index=dt) - assert_series_equal(expected, snow_coverage) + pd.testing.assert_series_equal( + expected, + snow_coverage, + atol=1e-5, + rtol=1e-5) def test_coverage_nrel_hourly_with_snow_depth(): @@ -72,7 +83,11 @@ def test_coverage_nrel_hourly_with_snow_depth(): covered = 1.0 - slide_amt * np.array([0, 1, 2, 3, 0, 0, 1, 0, 0]) expected = pd.Series(covered, index=dt) expected[snow_depth < threshold_depth] = 0 - assert_series_equal(expected, snow_coverage) + pd.testing.assert_series_equal( + expected, + snow_coverage, + atol=1e-5, + rtol=1e-5) def test_coverage_nrel_subhourly(): @@ -94,7 +109,11 @@ def test_coverage_nrel_subhourly(): 1.0 - slide_amt * np.array([1, 2, 3, 4, 5])) covered = np.append(covered, np.array([1., 1., 1., 1. - slide_amt])) expected = pd.Series(covered, index=dt) - assert_series_equal(expected, snow_coverage) + pd.testing.assert_series_equal( + expected, + snow_coverage, + atol=1e-5, + rtol=1e-5) def test_fully_covered_nrel_irregular(): @@ -106,7 +125,11 @@ def test_fully_covered_nrel_irregular(): threshold_snowfall=0.5) covered = np.array([False, False, True, False]) expected = pd.Series(covered, index=dt) - assert_series_equal(expected, snow_coverage) + pd.testing.assert_series_equal( + expected, + snow_coverage, + atol=1e-5, + rtol=1e-5) def test_coverage_nrel_initial(): @@ -125,7 +148,11 @@ def test_coverage_nrel_initial(): covered = 0.5 - slide_amt * np.array([0, 1, 2, 3, 4, 5, 6, 7]) covered = np.where(covered < 0, 0., covered) expected = pd.Series(covered, index=dt) - assert_series_equal(expected, snow_coverage) + pd.testing.assert_series_equal( + expected, + snow_coverage, + atol=1e-5, + rtol=1e-5) def test_dc_loss_nrel(): @@ -133,7 +160,7 @@ def test_dc_loss_nrel(): snow_coverage = pd.Series([1, 1, .5, .6, .2, .4, 0]) expected = pd.Series([1, 1, .5, .625, .25, .5, 0]) actual = snow.dc_loss_nrel(snow_coverage, num_strings) - assert_series_equal(expected, actual) + pd.testing.assert_series_equal(expected, actual, atol=1e-5, rtol=1e-5) def test__townsend_effective_snow(): diff --git a/tests/test_soiling.py b/tests/test_soiling.py index 53acc1c723..5df759def3 100644 --- a/tests/test_soiling.py +++ b/tests/test_soiling.py @@ -3,7 +3,6 @@ import datetime import numpy as np import pandas as pd -from .conftest import assert_series_equal from pvlib.soiling import hsu, kimber from pvlib.iotools import read_tmy3 from .conftest import TESTS_DATA_DIR, PVLIB_DATA_DIR @@ -95,7 +94,11 @@ def test_hsu_no_cleaning(rainfall_input, expected_output): result = hsu(rainfall=rainfall, cleaning_threshold=10., surface_tilt=tilt, pm2_5=pm2_5, pm10=pm10, depo_veloc=depo_veloc, rain_accum_period=pd.Timedelta('1h')) - assert_series_equal(result, expected_no_cleaning) + pd.testing.assert_series_equal( + result, + expected_no_cleaning, + atol=1e-5, + rtol=1e-5) def test_hsu(rainfall_input, expected_output_2): @@ -112,7 +115,11 @@ def test_hsu(rainfall_input, expected_output_2): pm2_5=pm2_5, pm10=pm10, depo_veloc=depo_veloc, rain_accum_period=pd.Timedelta('3h')) - assert_series_equal(result, expected_output_2) + pd.testing.assert_series_equal( + result, + expected_output_2, + atol=1e-5, + rtol=1e-5) def test_hsu_defaults(rainfall_input, expected_output_1): diff --git a/tests/test_solarposition.py b/tests/test_solarposition.py index 9ee1ad05ea..09fab8878a 100644 --- a/tests/test_solarposition.py +++ b/tests/test_solarposition.py @@ -13,7 +13,7 @@ from pvlib import solarposition, spa from pvlib.location import Location -from .conftest import (assert_frame_equal, assert_series_equal, requires_ephem, +from .conftest import (requires_ephem, requires_numba, requires_pandas_2_0, requires_spa_c) # setup times and locations to be tested. @@ -98,7 +98,11 @@ def test_spa_c_physical(expected_solpos, golden_mst): pressure=82000, temperature=11) expected_solpos.index = times - assert_frame_equal(expected_solpos, ephem_data[expected_solpos.columns]) + pd.testing.assert_frame_equal( + expected_solpos, + ephem_data[expected_solpos.columns], + atol=1e-5, + rtol=1e-5) @requires_spa_c @@ -110,7 +114,11 @@ def test_spa_c_physical_dst(expected_solpos, golden): pressure=82000, temperature=11) expected_solpos.index = times - assert_frame_equal(expected_solpos, ephem_data[expected_solpos.columns]) + pd.testing.assert_frame_equal( + expected_solpos, + ephem_data[expected_solpos.columns], + atol=1e-5, + rtol=1e-5) def test_spa_python_numpy_physical(expected_solpos, golden_mst): @@ -123,7 +131,11 @@ def test_spa_python_numpy_physical(expected_solpos, golden_mst): atmos_refract=0.5667, how='numpy') expected_solpos.index = times - assert_frame_equal(expected_solpos, ephem_data[expected_solpos.columns]) + pd.testing.assert_frame_equal( + expected_solpos, + ephem_data[expected_solpos.columns], + atol=1e-5, + rtol=1e-5) def test_spa_python_numpy_physical_dst(expected_solpos, golden): @@ -136,7 +148,11 @@ def test_spa_python_numpy_physical_dst(expected_solpos, golden): atmos_refract=0.5667, how='numpy') expected_solpos.index = times - assert_frame_equal(expected_solpos, ephem_data[expected_solpos.columns]) + pd.testing.assert_frame_equal( + expected_solpos, + ephem_data[expected_solpos.columns], + atol=1e-5, + rtol=1e-5) @pytest.mark.parametrize('delta_t', [65.0, None, np.array([65, 65])]) @@ -163,9 +179,10 @@ def test_sun_rise_set_transit_spa(expected_rise_set_spa, golden, delta_t): for col, data in result.items(): result_rounded[col] = data.dt.round('1s') - assert_frame_equal(frame, result_rounded, - check_dtype=False # ignore us/ns dtypes - ) + pd.testing.assert_frame_equal(frame, result_rounded, + check_dtype=False, atol=1e-5, rtol=1e-5 + # ignore us/ns dtypes + ) # test for Golden, CO compare to NLR SPA result = solarposition.sun_rise_set_transit_spa( @@ -178,9 +195,10 @@ def test_sun_rise_set_transit_spa(expected_rise_set_spa, golden, delta_t): for col, data in result.items(): result_rounded[col] = data.dt.round('s').tz_convert('MST') - assert_frame_equal(expected_rise_set_spa, result_rounded, - check_dtype=False # ignore us/ns dtypes - ) + pd.testing.assert_frame_equal(expected_rise_set_spa, result_rounded, + check_dtype=False, atol=1e-5, rtol=1e-5 + # ignore us/ns dtypes + ) def test_sun_rise_set_transit_spa_local_day(): @@ -215,7 +233,12 @@ def test_sun_rise_set_transit_spa_local_day(): for col, data in result.items(): result_rounded[col] = data.dt.round('1s') - assert_frame_equal(result_rounded, expected, check_dtype=False) + pd.testing.assert_frame_equal( + result_rounded, + expected, + check_dtype=False, + atol=1e-5, + rtol=1e-5) # positive-offset zone: early-morning-local timestamps are the *previous* # calendar day in UTC, the mirror of the case above @@ -247,7 +270,11 @@ def test_sun_rise_set_transit_ephem(expected_rise_set_ephem, golden): result_rounded = pd.DataFrame(index=result.index) for col, data in result.items(): result_rounded[col] = data.dt.round('min').tz_convert('MST') - assert_frame_equal(expected_rise_set_ephem, result_rounded) + pd.testing.assert_frame_equal( + expected_rise_set_ephem, + result_rounded, + atol=1e-5, + rtol=1e-5) # test next sunrise/sunset with times times = pd.DatetimeIndex([datetime.datetime(2015, 1, 2, 3, 0, 0), @@ -283,7 +310,11 @@ def test_sun_rise_set_transit_ephem(expected_rise_set_ephem, golden): result_rounded = pd.DataFrame(index=result.index) for col, data in result.items(): result_rounded[col] = data.dt.round('min').tz_convert('MST') - assert_frame_equal(expected, result_rounded) + pd.testing.assert_frame_equal( + expected, + result_rounded, + atol=1e-5, + rtol=1e-5) # test previous sunrise/sunset with times times = pd.DatetimeIndex([datetime.datetime(2015, 1, 2, 3, 0, 0), @@ -315,7 +346,11 @@ def test_sun_rise_set_transit_ephem(expected_rise_set_ephem, golden): result_rounded = pd.DataFrame(index=result.index) for col, data in result.items(): result_rounded[col] = data.dt.round('min').tz_convert('MST') - assert_frame_equal(expected, result_rounded) + pd.testing.assert_frame_equal( + expected, + result_rounded, + atol=1e-5, + rtol=1e-5) # test with different timezone times = times.tz_convert('UTC') @@ -330,7 +365,11 @@ def test_sun_rise_set_transit_ephem(expected_rise_set_ephem, golden): result_rounded = pd.DataFrame(index=result.index) for col, data in result.items(): result_rounded[col] = data.dt.round('min').tz_convert(times.tz) - assert_frame_equal(expected, result_rounded) + pd.testing.assert_frame_equal( + expected, + result_rounded, + atol=1e-5, + rtol=1e-5) @requires_ephem @@ -366,7 +405,11 @@ def test_sun_rise_set_transit_ephem_horizon(golden): expected = pd.Series(index=times, data=[sunrise_delta], name='sunrise').dt.round('min') - assert_series_equal(expected, result_rounded) + pd.testing.assert_series_equal( + expected, + result_rounded, + atol=1e-5, + rtol=1e-5) @requires_ephem @@ -377,8 +420,11 @@ def test_pyephem_physical(expected_solpos, golden_mst): golden_mst.longitude, pressure=82000, temperature=11) expected_solpos.index = times - assert_frame_equal(expected_solpos.round(2), - ephem_data[expected_solpos.columns].round(2)) + pd.testing.assert_frame_equal( + expected_solpos.round(2), + ephem_data[expected_solpos.columns].round(2), + atol=1e-5, + rtol=1e-5) @requires_ephem @@ -389,8 +435,11 @@ def test_pyephem_physical_dst(expected_solpos, golden): golden.longitude, pressure=82000, temperature=11) expected_solpos.index = times - assert_frame_equal(expected_solpos.round(2), - ephem_data[expected_solpos.columns].round(2)) + pd.testing.assert_frame_equal( + expected_solpos.round(2), + ephem_data[expected_solpos.columns].round(2), + atol=1e-5, + rtol=1e-5) @requires_ephem @@ -435,7 +484,11 @@ def test_ephemeris_physical(expected_solpos, golden_mst): expected_solpos.index = times expected_solpos = np.round(expected_solpos, 2) ephem_data = np.round(ephem_data, 2) - assert_frame_equal(expected_solpos, ephem_data[expected_solpos.columns]) + pd.testing.assert_frame_equal( + expected_solpos, + ephem_data[expected_solpos.columns], + atol=1e-5, + rtol=1e-5) def test_ephemeris_physical_dst(expected_solpos, golden): @@ -447,7 +500,11 @@ def test_ephemeris_physical_dst(expected_solpos, golden): expected_solpos.index = times expected_solpos = np.round(expected_solpos, 2) ephem_data = np.round(ephem_data, 2) - assert_frame_equal(expected_solpos, ephem_data[expected_solpos.columns]) + pd.testing.assert_frame_equal( + expected_solpos, + ephem_data[expected_solpos.columns], + atol=1e-5, + rtol=1e-5) def test_ephemeris_physical_no_tz(expected_solpos, golden_mst): @@ -460,7 +517,11 @@ def test_ephemeris_physical_no_tz(expected_solpos, golden_mst): expected_solpos.index = times expected_solpos = np.round(expected_solpos, 2) ephem_data = np.round(ephem_data, 2) - assert_frame_equal(expected_solpos, ephem_data[expected_solpos.columns]) + pd.testing.assert_frame_equal( + expected_solpos, + ephem_data[expected_solpos.columns], + atol=1e-5, + rtol=1e-5) def test_get_solarposition_error(golden): @@ -497,7 +558,11 @@ def test_get_solarposition_pressure( this_expected.index = times this_expected = np.round(this_expected, 5) ephem_data = np.round(ephem_data, 5) - assert_frame_equal(this_expected, ephem_data[this_expected.columns]) + pd.testing.assert_frame_equal( + this_expected, + ephem_data[this_expected.columns], + atol=1e-5, + rtol=1e-5) @pytest.mark.parametrize("altitude, expected", [ @@ -523,7 +588,11 @@ def test_get_solarposition_altitude( this_expected.index = times this_expected = np.round(this_expected, 5) ephem_data = np.round(ephem_data, 5) - assert_frame_equal(this_expected, ephem_data[this_expected.columns]) + pd.testing.assert_frame_equal( + this_expected, + ephem_data[this_expected.columns], + atol=1e-5, + rtol=1e-5) @pytest.mark.parametrize("delta_t, method", [ @@ -552,7 +621,11 @@ def test_get_solarposition_deltat(delta_t, method, expected_solpos_multi, this_expected.index = times this_expected = np.round(this_expected, 5) ephem_data = np.round(ephem_data, 5) - assert_frame_equal(this_expected, ephem_data[this_expected.columns]) + pd.testing.assert_frame_equal( + this_expected, + ephem_data[this_expected.columns], + atol=1e-5, + rtol=1e-5) @pytest.mark.parametrize("method", ['nrel_numba', 'nrel_numpy']) @@ -567,7 +640,12 @@ def test_spa_array_delta_t(method): delta_t=np.array([67, 0]), method=method) - assert_series_equal(ephem_data['azimuth'], expected, check_names=False) + pd.testing.assert_series_equal( + ephem_data['azimuth'], + expected, + check_names=False, + atol=1e-5, + rtol=1e-5) def test_get_solarposition_no_kwargs(expected_solpos, golden): @@ -578,7 +656,11 @@ def test_get_solarposition_no_kwargs(expected_solpos, golden): expected_solpos.index = times expected_solpos = np.round(expected_solpos, 2) ephem_data = np.round(ephem_data, 2) - assert_frame_equal(expected_solpos, ephem_data[expected_solpos.columns]) + pd.testing.assert_frame_equal( + expected_solpos, + ephem_data[expected_solpos.columns], + atol=1e-5, + rtol=1e-5) @requires_ephem @@ -591,7 +673,11 @@ def test_get_solarposition_method_pyephem(expected_solpos, golden): expected_solpos.index = times expected_solpos = np.round(expected_solpos, 2) ephem_data = np.round(ephem_data, 2) - assert_frame_equal(expected_solpos, ephem_data[expected_solpos.columns]) + pd.testing.assert_frame_equal( + expected_solpos, + ephem_data[expected_solpos.columns], + atol=1e-5, + rtol=1e-5) @pytest.mark.parametrize('delta_t', [64.0, None, np.array([64, 64])]) @@ -602,14 +688,14 @@ def test_nrel_earthsun_distance(delta_t): result = solarposition.nrel_earthsun_distance(times, delta_t=delta_t) expected = pd.Series(np.array([0.983289204601, 1.01486146446]), index=times) - assert_series_equal(expected, result) + pd.testing.assert_series_equal(expected, result, atol=1e-5, rtol=1e-5) if np.size(delta_t) == 1: # skip the array delta_t times = datetime.datetime(2015, 1, 2) result = solarposition.nrel_earthsun_distance(times, delta_t=delta_t) expected = pd.Series(np.array([0.983289204601]), index=pd.DatetimeIndex([times, ])) - assert_series_equal(expected, result) + pd.testing.assert_series_equal(expected, result, atol=1e-5, rtol=1e-5) def test_equation_of_time(): @@ -916,7 +1002,12 @@ def test_get_solarposition_microsecond_index(method, tz): sp_ns = solarposition.get_solarposition(index_ns, 0, 0, method=method) sp_us = solarposition.get_solarposition(index_us, 0, 0, method=method) - assert_frame_equal(sp_ns, sp_us, check_index_type=False) + pd.testing.assert_frame_equal( + sp_ns, + sp_us, + check_index_type=False, + atol=1e-5, + rtol=1e-5) @requires_pandas_2_0 @@ -932,7 +1023,12 @@ def test_nrel_earthsun_distance_microsecond_index(tz): esd_ns = solarposition.nrel_earthsun_distance(index_ns) esd_us = solarposition.nrel_earthsun_distance(index_us) - assert_series_equal(esd_ns, esd_us, check_index_type=False) + pd.testing.assert_series_equal( + esd_ns, + esd_us, + check_index_type=False, + atol=1e-5, + rtol=1e-5) @requires_pandas_2_0 @@ -964,7 +1060,12 @@ def test_rise_set_transit_spa_microsecond_index(tz): rst_ns = solarposition.sun_rise_set_transit_spa(index_ns, 40, -80) rst_us = solarposition.sun_rise_set_transit_spa(index_us, 40, -80) - assert_frame_equal(rst_ns, rst_us, check_index_type=False) + pd.testing.assert_frame_equal( + rst_ns, + rst_us, + check_index_type=False, + atol=1e-5, + rtol=1e-5) @requires_pandas_2_0 @@ -1011,7 +1112,11 @@ def test_spa_python_numba_physical(expected_solpos, golden_mst): atmos_refract=0.5667, how='numba', numthreads=1) expected_solpos.index = times - assert_frame_equal(expected_solpos, ephem_data[expected_solpos.columns]) + pd.testing.assert_frame_equal( + expected_solpos, + ephem_data[expected_solpos.columns], + atol=1e-5, + rtol=1e-5) @requires_numba @@ -1028,7 +1133,11 @@ def test_spa_python_numba_physical_dst(expected_solpos, golden): atmos_refract=0.5667, how='numba', numthreads=1) expected_solpos.index = times - assert_frame_equal(expected_solpos, ephem_data[expected_solpos.columns]) + pd.testing.assert_frame_equal( + expected_solpos, + ephem_data[expected_solpos.columns], + atol=1e-5, + rtol=1e-5) with pytest.warns(UserWarning): # test that we get a warning when reloading to use numpy only diff --git a/tests/test_temperature.py b/tests/test_temperature.py index f7cc242477..6cf1fed660 100644 --- a/tests/test_temperature.py +++ b/tests/test_temperature.py @@ -2,7 +2,7 @@ import numpy as np import pytest -from .conftest import TESTS_DATA_DIR, assert_series_equal +from .conftest import TESTS_DATA_DIR from numpy.testing import assert_allclose from pvlib import temperature, tools @@ -63,8 +63,16 @@ def test_sapm_series(sapm_default): sapm_default['b']) expected_cell = pd.Series([0., 23.06066166, 5.], index=times) expected_module = pd.Series([0., 21.56066166, 5.], index=times) - assert_series_equal(expected_cell, cell_temps) - assert_series_equal(expected_module, module_temps) + pd.testing.assert_series_equal( + expected_cell, + cell_temps, + atol=1e-5, + rtol=1e-5) + pd.testing.assert_series_equal( + expected_module, + module_temps, + atol=1e-5, + rtol=1e-5) def test_pvsyst_cell_default(): @@ -95,7 +103,7 @@ def test_pvsyst_cell_series(): result = temperature.pvsyst_cell(irrads, temps, wind_speed=winds) expected = pd.Series([0.0, 23.965517, 5.0], index=times) - assert_series_equal(expected, result) + pd.testing.assert_series_equal(expected, result, atol=1e-5, rtol=1e-5) def test_faiman_default(): @@ -201,7 +209,7 @@ def test_faiman_series(): result = temperature.faiman(irrads, temps, wind_speed=winds) expected = pd.Series([0.0, 18.446, 5.0], index=times) - assert_series_equal(expected, result) + pd.testing.assert_series_equal(expected, result, atol=1e-5, rtol=1e-5) def test__temperature_model_params(): @@ -250,8 +258,11 @@ def test_fuentes(filename, inoct): is_daytime = (inputs['poa_global'] > 0) & ~is_dawn # the accuracy is probably higher than 3 digits here, but the PVWatts # export data has low precision so can only test up to 3 digits - assert_series_equal(expected_tcell[is_daytime].round(3), - actual_tcell[is_daytime].round(3)) + pd.testing.assert_series_equal( + expected_tcell[is_daytime].round(3), + actual_tcell[is_daytime].round(3), + atol=1e-5, + rtol=1e-5) # use lower precision for dawn times to accommodate the dawn transient error = actual_tcell[is_dawn] - expected_tcell[is_dawn] assert (error.abs() < 0.1).all() @@ -271,8 +282,11 @@ def test_fuentes_timezone(tz): out = temperature.fuentes(df['poa_global'], df['temp_air'], df['wind_speed'], noct_installed=45) - assert_series_equal(out, pd.Series([48.042, 51.845, 51.846], index=index, - name='tmod')) + pd.testing.assert_series_equal( + out, + pd.Series([48.042, 51.845, 51.846], index=index, name='tmod'), + atol=1e-5, + rtol=1e-5) # GH 2608 df = pd.DataFrame({'poa_global': 1000., 'temp_air': 20., 'wind_speed': 1.}, index) @@ -280,8 +294,11 @@ def test_fuentes_timezone(tz): out = temperature.fuentes(df['poa_global'], df['temp_air'], df['wind_speed'], noct_installed=45) - assert_series_equal(out, pd.Series([48.042, 51.845, 51.846], index=index, - name='tmod')) + pd.testing.assert_series_equal( + out, + pd.Series([48.042, 51.845, 51.846], index=index, name='tmod'), + atol=1e-5, + rtol=1e-5) def test_noct_sam(): @@ -303,7 +320,11 @@ def test_noct_sam(): pd.Series(index=dr, data=wind_speed), pd.Series(index=dr, data=noct), module_efficiency) - assert_series_equal(result, pd.Series(index=dr, data=expected)) + pd.testing.assert_series_equal( + result, + pd.Series(index=dr, data=expected), + atol=1e-5, + rtol=1e-5) def test_noct_sam_against_sam(): @@ -367,7 +388,7 @@ def test_prilliman(): expected = pd.Series([0, 0, 0.7047457, 2.21176412, 4.45584299, 7.63635512, 12.26808265, 18.00305776], index=times) actual = temperature.prilliman(cell_temperature, wind_speed, unit_mass=10) - assert_series_equal(expected, actual) + pd.testing.assert_series_equal(expected, actual, atol=1e-5, rtol=1e-5) # custom coeffs coefficients = [0.0046, 4.5537e-4, -2.2586e-4, -1.5661e-5] @@ -375,7 +396,7 @@ def test_prilliman(): 12.30423167, 18.04215198], index=times) actual = temperature.prilliman(cell_temperature, wind_speed, unit_mass=10, coefficients=coefficients) - assert_series_equal(expected, actual) + pd.testing.assert_series_equal(expected, actual, atol=1e-5, rtol=1e-5) # even very short inputs < 20 minutes total still work times = pd.date_range('2019-01-01', freq='1min', periods=8) @@ -384,7 +405,7 @@ def test_prilliman(): expected = pd.Series([0, 0, 0.53557976, 1.49270094, 2.85940173, 4.63914366, 7.09641845, 10.24899272], index=times) actual = temperature.prilliman(cell_temperature, wind_speed, unit_mass=12) - assert_series_equal(expected, actual) + pd.testing.assert_series_equal(expected, actual, atol=1e-5, rtol=1e-5) def test_prilliman_coarse(): @@ -399,7 +420,11 @@ def test_prilliman_coarse(): "input temperature series unchanged") with pytest.warns(UserWarning, match=msg): actual = temperature.prilliman(cell_temperature, wind_speed) - assert_series_equal(cell_temperature, actual) + pd.testing.assert_series_equal( + cell_temperature, + actual, + atol=1e-5, + rtol=1e-5) def test_prilliman_nans(): @@ -411,7 +436,11 @@ def test_prilliman_nans(): actual = temperature.prilliman(cell_temperature, wind_speed) expected = pd.Series([True, True, True, True, True, True, False, True], index=times) - assert_series_equal(actual.notnull(), expected) + pd.testing.assert_series_equal( + actual.notnull(), + expected, + atol=1e-5, + rtol=1e-5) # check that nan temperatures do not mess up the weighted average; # the original implementation did not set weight=0 for nan values, @@ -422,7 +451,7 @@ def test_prilliman_nans(): actual = temperature.prilliman(cell_temperature, wind_speed) # original implementation would return some values < 1 here expected = pd.Series(1., index=times) - assert_series_equal(actual, expected) + pd.testing.assert_series_equal(actual, expected, atol=1e-5, rtol=1e-5) def test_glm_conversions(): diff --git a/tests/test_tracking.py b/tests/test_tracking.py index 5e9b09f25f..f510c67be5 100644 --- a/tests/test_tracking.py +++ b/tests/test_tracking.py @@ -7,7 +7,7 @@ import pvlib from pvlib import tracking -from .conftest import TESTS_DATA_DIR, assert_frame_equal, assert_series_equal +from .conftest import TESTS_DATA_DIR SINGLEAXIS_COL_ORDER = ['tracker_theta', 'aoi', 'surface_azimuth', 'surface_tilt'] @@ -27,7 +27,7 @@ def test_solar_noon(): index=index, dtype=np.float64) expect = expect[SINGLEAXIS_COL_ORDER] - assert_frame_equal(expect, tracker_data) + pd.testing.assert_frame_equal(expect, tracker_data, atol=1e-5, rtol=1e-5) def test_scalars(): @@ -86,7 +86,7 @@ def test_nans(): [nan, nan, nan, nan], [nan, nan, nan, nan]]), columns=['tracker_theta', 'aoi', 'surface_azimuth', 'surface_tilt']) - assert_frame_equal(tracker_data, expect) + pd.testing.assert_frame_equal(tracker_data, expect, atol=1e-5, rtol=1e-5) def test_arrays_multi(): @@ -122,7 +122,7 @@ def test_azimuth_north_south(): index=[0], dtype=np.float64) expect = expect[SINGLEAXIS_COL_ORDER] - assert_frame_equal(expect, tracker_data) + pd.testing.assert_frame_equal(expect, tracker_data, atol=1e-5, rtol=1e-5) tracker_data = tracking.singleaxis(apparent_zenith, apparent_azimuth, axis_tilt=0, axis_azimuth=0, @@ -131,7 +131,7 @@ def test_azimuth_north_south(): expect['tracker_theta'] *= -1 - assert_frame_equal(expect, tracker_data) + pd.testing.assert_frame_equal(expect, tracker_data, atol=1e-5, rtol=1e-5) def test_max_angle(): @@ -147,7 +147,7 @@ def test_max_angle(): index=[0], dtype=np.float64) expect = expect[SINGLEAXIS_COL_ORDER] - assert_frame_equal(expect, tracker_data) + pd.testing.assert_frame_equal(expect, tracker_data, atol=1e-5, rtol=1e-5) def test_min_angle(): @@ -163,7 +163,7 @@ def test_min_angle(): index=[0], dtype=np.float64) expect = expect[SINGLEAXIS_COL_ORDER] - assert_frame_equal(expect, tracker_data) + pd.testing.assert_frame_equal(expect, tracker_data, atol=1e-5, rtol=1e-5) def test_backtrack(): @@ -180,7 +180,7 @@ def test_backtrack(): index=[0], dtype=np.float64) expect = expect[SINGLEAXIS_COL_ORDER] - assert_frame_equal(expect, tracker_data) + pd.testing.assert_frame_equal(expect, tracker_data, atol=1e-5, rtol=1e-5) tracker_data = tracking.singleaxis(apparent_zenith, apparent_azimuth, axis_tilt=0, axis_azimuth=0, @@ -192,7 +192,7 @@ def test_backtrack(): index=[0], dtype=np.float64) expect = expect[SINGLEAXIS_COL_ORDER] - assert_frame_equal(expect, tracker_data) + pd.testing.assert_frame_equal(expect, tracker_data, atol=1e-5, rtol=1e-5) def test__unit_normal(): @@ -258,7 +258,7 @@ def test_axis_tilt(): index=[0], dtype=np.float64) expect = expect[SINGLEAXIS_COL_ORDER] - assert_frame_equal(expect, tracker_data) + pd.testing.assert_frame_equal(expect, tracker_data, atol=1e-5, rtol=1e-5) tracker_data = tracking.singleaxis(apparent_zenith, apparent_azimuth, axis_tilt=30, axis_azimuth=0, @@ -270,7 +270,7 @@ def test_axis_tilt(): index=[0], dtype=np.float64) expect = expect[SINGLEAXIS_COL_ORDER] - assert_frame_equal(expect, tracker_data) + pd.testing.assert_frame_equal(expect, tracker_data, atol=1e-5, rtol=1e-5) def test_axis_azimuth(): @@ -288,7 +288,7 @@ def test_axis_azimuth(): index=[0], dtype=np.float64) expect = expect[SINGLEAXIS_COL_ORDER] - assert_frame_equal(expect, tracker_data) + pd.testing.assert_frame_equal(expect, tracker_data, atol=1e-5, rtol=1e-5) # sun to the east, horizontal south-oriented tracker apparent_zenith = pd.Series([30]) @@ -304,7 +304,7 @@ def test_axis_azimuth(): index=[0], dtype=np.float64) expect = expect[SINGLEAXIS_COL_ORDER] - assert_frame_equal(expect, tracker_data) + pd.testing.assert_frame_equal(expect, tracker_data, atol=1e-5, rtol=1e-5) # sun to the south, horizontal east-oriented tracker apparent_zenith = pd.Series([30]) @@ -320,7 +320,7 @@ def test_axis_azimuth(): index=[0], dtype=np.float64) expect = expect[SINGLEAXIS_COL_ORDER] - assert_frame_equal(expect, tracker_data) + pd.testing.assert_frame_equal(expect, tracker_data, atol=1e-5, rtol=1e-5) def test_horizon_flat(): @@ -338,7 +338,7 @@ def test_horizon_flat(): [ 0., 45., 90., 0.], [ nan, nan, nan, nan]]), columns=['tracker_theta', 'aoi', 'surface_azimuth', 'surface_tilt']) - assert_frame_equal(out, expected) + pd.testing.assert_frame_equal(out, expected, atol=1e-5, rtol=1e-5) def test_horizon_tilted(): @@ -354,7 +354,7 @@ def test_horizon_tilted(): [ 0., 45., 180., 90.], [ 179., 45., 359., 90.]]), columns=['tracker_theta', 'aoi', 'surface_azimuth', 'surface_tilt']) - assert_frame_equal(out, expected) + pd.testing.assert_frame_equal(out, expected, atol=1e-5, rtol=1e-5) def test_low_sun_angles(): @@ -443,16 +443,20 @@ def test_slope_aware_backtracking(): 90.0-expected_data['ApparentElevation'], expected_data['SolarAzimuth'], axis_tilt, axis_azimuth, max_angle=90.0, backtrack=True, gcr=0.5, cross_axis_tilt=cross_axis_tilt) - assert_series_equal(sat['tracker_theta'], - expected_data['Backtracking'].rename('tracker_theta'), - check_less_precise=True) + pd.testing.assert_series_equal( + sat['tracker_theta'], + expected_data['Backtracking'].rename('tracker_theta'), + atol=1e-3, + rtol=1e-3) truetracking = tracking.singleaxis( 90.0-expected_data['ApparentElevation'], expected_data['SolarAzimuth'], axis_tilt, axis_azimuth, max_angle=90.0, backtrack=False, gcr=0.5, cross_axis_tilt=cross_axis_tilt) - assert_series_equal(truetracking['tracker_theta'], - expected_data['TrueTracking'].rename('tracker_theta'), - check_less_precise=True) + pd.testing.assert_series_equal( + truetracking['tracker_theta'], + expected_data['TrueTracking'].rename('tracker_theta'), + atol=1e-3, + rtol=1e-3) def test_singleaxis_neg_axis_tilt(): @@ -502,8 +506,16 @@ def test_calc_surface_orientation_types(): expected_tilts = pd.Series(expected_tilts).rename('surface_tilt') expected_azimuths = pd.Series(expected_azimuths).rename('surface_azimuth') out = tracking.calc_surface_orientation(tracker_theta=rotations) - assert_series_equal(expected_tilts, out['surface_tilt']) - assert_series_equal(expected_azimuths, out['surface_azimuth']) + pd.testing.assert_series_equal( + expected_tilts, + out['surface_tilt'], + atol=1e-5, + rtol=1e-5) + pd.testing.assert_series_equal( + expected_azimuths, + out['surface_azimuth'], + atol=1e-5, + rtol=1e-5) # float for rotation, expected_tilt, expected_azimuth in zip( From 99cf939d6c94c24b32dcf8dddfb817078559cc18 Mon Sep 17 00:00:00 2001 From: DresdenGman Date: Sat, 21 Nov 2026 02:40:57 +0000 Subject: [PATCH 2/2] Fix flake8-linter failures in #2951 follow-up - test_sodapro.py: drop unused pvlibDeprecationWarning import (F401) - test_location.py: reformat the six clearsky expected-DataFrame constructions to a flake8-clean layout (E126/E202/E203/E131 were pre-existing style issues surfaced by --diff on the touched hunks); all six frames verified numerically identical via assert_frame_equal --- tests/iotools/test_sodapro.py | 2 - tests/test_location.py | 126 +++++++++++++++++++++------------- 2 files changed, 78 insertions(+), 50 deletions(-) diff --git a/tests/iotools/test_sodapro.py b/tests/iotools/test_sodapro.py index 1b38e46ba7..8b28a66744 100644 --- a/tests/iotools/test_sodapro.py +++ b/tests/iotools/test_sodapro.py @@ -11,8 +11,6 @@ from tests.conftest import TESTS_DATA_DIR -from pvlib._deprecation import pvlibDeprecationWarning - testfile_mcclear_verbose = TESTS_DATA_DIR / 'cams_mcclear_1min_verbose.csv' testfile_mcclear_monthly = TESTS_DATA_DIR / 'cams_mcclear_monthly.csv' testfile_radiation_verbose = TESTS_DATA_DIR / 'cams_radiation_1min_verbose.csv' diff --git a/tests/test_location.py b/tests/test_location.py index 43479a86d9..4bfcebea91 100644 --- a/tests/test_location.py +++ b/tests/test_location.py @@ -162,28 +162,38 @@ def test_get_clearsky_ineichen_supply_linke(mocker): def test_get_clearsky_haurwitz(times): tus = Location(32.2, -111, 'US/Arizona', 700, 'Tucson') clearsky = tus.get_clearsky(times, model='haurwitz') - expected = pd.DataFrame(data=np.array( - [[ 0. ], - [ 242.30085588], - [ 559.38247117], - [ 384.6873791 ], - [ 0. ]]), - columns=['ghi'], - index=times) + expected = pd.DataFrame( + data=np.array( + [ + [0.0], + [242.30085588], + [559.38247117], + [384.6873791], + [0.0], + ] + ), + columns=['ghi'], + index=times, + ) pd.testing.assert_frame_equal(expected, clearsky, atol=1e-5, rtol=1e-5) def test_get_clearsky_simplified_solis(times): tus = Location(32.2, -111, 'US/Arizona', 700, 'Tucson') clearsky = tus.get_clearsky(times, model='simplified_solis') - expected = pd.DataFrame(data=np. - array([[ 0. , 0. , 0. ], - [ 70.00146271, 638.01145669, 236.71136245], - [ 101.69729217, 852.51950946, 577.1117803 ], - [ 86.1679965 , 755.98048017, 385.59586091], - [ 0. , 0. , 0. ]]), - columns=['dhi', 'dni', 'ghi'], - index=times) + expected = pd.DataFrame( + data=np.array( + [ + [0.0, 0.0, 0.0], + [70.00146271, 638.01145669, 236.71136245], + [101.69729217, 852.51950946, 577.1117803], + [86.1679965, 755.98048017, 385.59586091], + [0.0, 0.0, 0.0], + ] + ), + columns=['dhi', 'dni', 'ghi'], + index=times, + ) expected = expected[['ghi', 'dni', 'dhi']] pd.testing.assert_frame_equal(expected, clearsky, atol=1e-3, rtol=1e-3) @@ -194,14 +204,19 @@ def test_get_clearsky_simplified_solis_apparent_elevation(times): 'apparent_zenith': pd.Series(10, index=times)} clearsky = tus.get_clearsky(times, model='simplified_solis', solar_position=solar_position) - expected = pd.DataFrame(data=np. - array([[ 131.3124497 , 1001.14754036, 1108.14147919], - [ 131.3124497 , 1001.14754036, 1108.14147919], - [ 131.3124497 , 1001.14754036, 1108.14147919], - [ 131.3124497 , 1001.14754036, 1108.14147919], - [ 131.3124497 , 1001.14754036, 1108.14147919]]), - columns=['dhi', 'dni', 'ghi'], - index=times) + expected = pd.DataFrame( + data=np.array( + [ + [131.3124497, 1001.14754036, 1108.14147919], + [131.3124497, 1001.14754036, 1108.14147919], + [131.3124497, 1001.14754036, 1108.14147919], + [131.3124497, 1001.14754036, 1108.14147919], + [131.3124497, 1001.14754036, 1108.14147919], + ] + ), + columns=['dhi', 'dni', 'ghi'], + index=times, + ) expected = expected[['ghi', 'dni', 'dhi']] pd.testing.assert_frame_equal(expected, clearsky, atol=1e-3, rtol=1e-3) @@ -210,14 +225,19 @@ def test_get_clearsky_simplified_solis_dni_extra(times): tus = Location(32.2, -111, 'US/Arizona', 700, 'Tucson') clearsky = tus.get_clearsky(times, model='simplified_solis', dni_extra=1370) - expected = pd.DataFrame(data=np. - array([[ 0. , 0. , 0. ], - [ 67.82281485, 618.15469596, 229.34422063], - [ 98.53217848, 825.98663808, 559.15039353], - [ 83.48619937, 732.45218243, 373.59500313], - [ 0. , 0. , 0. ]]), - columns=['dhi', 'dni', 'ghi'], - index=times) + expected = pd.DataFrame( + data=np.array( + [ + [0.0, 0.0, 0.0], + [67.82281485, 618.15469596, 229.34422063], + [98.53217848, 825.98663808, 559.15039353], + [83.48619937, 732.45218243, 373.59500313], + [0.0, 0.0, 0.0], + ] + ), + columns=['dhi', 'dni', 'ghi'], + index=times, + ) expected = expected[['ghi', 'dni', 'dhi']] pd.testing.assert_frame_equal(expected, clearsky, atol=1e-5, rtol=1e-5) @@ -226,14 +246,19 @@ def test_get_clearsky_simplified_solis_pressure(times): tus = Location(32.2, -111, 'US/Arizona', 700, 'Tucson') clearsky = tus.get_clearsky(times, model='simplified_solis', pressure=95000) - expected = pd.DataFrame(data=np. - array([[ 0. , 0. , 0. ], - [ 70.20556637, 635.53091983, 236.17716435], - [ 102.08954904, 850.49502085, 576.28465815], - [ 86.46561686, 753.70744638, 384.90537859], - [ 0. , 0. , 0. ]]), - columns=['dhi', 'dni', 'ghi'], - index=times) + expected = pd.DataFrame( + data=np.array( + [ + [0.0, 0.0, 0.0], + [70.20556637, 635.53091983, 236.17716435], + [102.08954904, 850.49502085, 576.28465815], + [86.46561686, 753.70744638, 384.90537859], + [0.0, 0.0, 0.0], + ] + ), + columns=['dhi', 'dni', 'ghi'], + index=times, + ) expected = expected[['ghi', 'dni', 'dhi']] pd.testing.assert_frame_equal(expected, clearsky, atol=1e-3, rtol=1e-3) @@ -242,14 +267,19 @@ def test_get_clearsky_simplified_solis_aod_pw(times): tus = Location(32.2, -111, 'US/Arizona', 700, 'Tucson') clearsky = tus.get_clearsky(times, model='simplified_solis', aod700=0.25, precipitable_water=2.) - expected = pd.DataFrame(data=np. - array([[ 0. , 0. , 0. ], - [ 85.77821205, 374.58084365, 179.48483117], - [ 143.52743364, 625.91745295, 490.06254157], - [ 114.63275842, 506.52275195, 312.24711495], - [ 0. , 0. , 0. ]]), - columns=['dhi', 'dni', 'ghi'], - index=times) + expected = pd.DataFrame( + data=np.array( + [ + [0.0, 0.0, 0.0], + [85.77821205, 374.58084365, 179.48483117], + [143.52743364, 625.91745295, 490.06254157], + [114.63275842, 506.52275195, 312.24711495], + [0.0, 0.0, 0.0], + ] + ), + columns=['dhi', 'dni', 'ghi'], + index=times, + ) expected = expected[['ghi', 'dni', 'dhi']] pd.testing.assert_frame_equal(expected, clearsky, atol=1e-3, rtol=1e-3)