From add4b4d6900191f0672d4431ab6b60f8c2151d81 Mon Sep 17 00:00:00 2001 From: "Alyssa J. Sockol" <49569746+ajsockol@users.noreply.github.com> Date: Wed, 17 Jul 2024 14:13:29 -0500 Subject: [PATCH] Updating unit tests --- tests/utils/test_data_utils.py | 40 ++++++++++++---------------------- 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/tests/utils/test_data_utils.py b/tests/utils/test_data_utils.py index 166d3ffa13..fa1c66b0ef 100644 --- a/tests/utils/test_data_utils.py +++ b/tests/utils/test_data_utils.py @@ -566,6 +566,7 @@ def test_convert_2d_to_1d(): ds = xr.Dataset({ 'var': (('time', 'level'), data) }, coords={'time': [0, 1, 2], 'level': [10, 20]}) + ds['level'].attrs['units'] = 'm' # Run the function result = convert_2d_to_1d(ds, parse='level') @@ -576,26 +577,6 @@ def test_convert_2d_to_1d(): np.testing.assert_array_equal(result['var_level_0'].values, [1, 3, 5]) np.testing.assert_array_equal(result['var_level_1'].values, [2, 4, 6]) - # Create a sample dataset - data = np.array([[1], [3], [5]]) - ds = xr.Dataset({ - 'var': (('time', 'level'), data) - }, coords={'time': [0, 1, 2], 'level': [10]}) - - # Run the function with keep_name_if_one=True - result = convert_2d_to_1d(ds, parse='level', keep_name_if_one=True) - - # Check the results - assert 'var' in result - np.testing.assert_array_equal(result['var'].values, [1, 3, 5]) - - # Create a sample dataset - data = np.array([[1, 2], [3, 4], [5, 6]]) - ds = xr.Dataset({ - 'var': (('time', 'level'), data) - }, coords={'time': [0, 1, 2], 'level': [10, 20]}) - ds['level'].attrs['units'] = 'm' - # Run the function with use_dim_value_in_name=True result = convert_2d_to_1d(ds, parse='level', use_dim_value_in_name=True) @@ -605,12 +586,6 @@ def test_convert_2d_to_1d(): np.testing.assert_array_equal(result['var_level_10m'].values, [1, 3, 5]) np.testing.assert_array_equal(result['var_level_20m'].values, [2, 4, 6]) - # Create a sample dataset - data = np.array([[1, 2], [3, 4], [5, 6]]) - ds = xr.Dataset({ - 'var': (('time', 'level'), data) - }, coords={'time': [0, 1, 2], 'level': [10, 20]}) - # Run the function with custom labels result = convert_2d_to_1d(ds, parse='level', dim_labels=['low', 'high']) @@ -619,3 +594,16 @@ def test_convert_2d_to_1d(): assert 'var_high' in result np.testing.assert_array_equal(result['var_low'].values, [1, 3, 5]) np.testing.assert_array_equal(result['var_high'].values, [2, 4, 6]) + + # Create a sample dataset + data = np.array([[1], [3], [5]]) + ds = xr.Dataset({ + 'var': (('time', 'level'), data) + }, coords={'time': [0, 1, 2], 'level': [10]}) + + # Run the function with keep_name_if_one=True + result = convert_2d_to_1d(ds, parse='level', keep_name_if_one=True) + + # Check the results + assert 'var' in result + np.testing.assert_array_equal(result['var'].values, [1, 3, 5])