From 507cc1b3e12753b5fa254ecb087e55d9b5f27f58 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Thu, 11 Jan 2024 15:37:47 +1300 Subject: [PATCH 1/2] Make deepcopy of tracks before setting NaN values So that the modified tracks won't be used in other test functions, causing tests to fail. --- pygmt/tests/test_x2sys_cross.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pygmt/tests/test_x2sys_cross.py b/pygmt/tests/test_x2sys_cross.py index 96f3bbd2ef1..75374cece6c 100644 --- a/pygmt/tests/test_x2sys_cross.py +++ b/pygmt/tests/test_x2sys_cross.py @@ -1,6 +1,7 @@ """ Test pygmt.x2sys_cross. """ +import copy import os from pathlib import Path from tempfile import TemporaryDirectory @@ -142,8 +143,9 @@ def test_x2sys_cross_input_dataframe_with_nan(tracks): tag=tag, fmtfile="xyz", suffix="xyzt", units=["de", "se"], force=True ) - tracks[0].loc[tracks[0]["z"] < -15, "z"] = np.nan # set some values to NaN - output = x2sys_cross(tracks=tracks, tag=tag, coe="i") + newtracks = copy.deepcopy(x=tracks) + newtracks[0].loc[newtracks[0]["z"] < -15, "z"] = np.nan # set some NaN values + output = x2sys_cross(tracks=newtracks, tag=tag, coe="i") assert isinstance(output, pd.DataFrame) assert output.shape == (3, 12) From a0fcbb59026abefba4abf5defde5f9adfd2c94fa Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Thu, 11 Jan 2024 15:39:40 +1300 Subject: [PATCH 2/2] Update output shape and mean values from some x2sys_cross tests Small changes to the number of output rows, and the mean value of the z_X and z_M/z_1/z_2 columns. --- pygmt/tests/test_x2sys_cross.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pygmt/tests/test_x2sys_cross.py b/pygmt/tests/test_x2sys_cross.py index 75374cece6c..17638d83c45 100644 --- a/pygmt/tests/test_x2sys_cross.py +++ b/pygmt/tests/test_x2sys_cross.py @@ -66,7 +66,7 @@ def test_x2sys_cross_input_file_output_dataframe(): output = x2sys_cross(tracks=["@tut_ship.xyz"], tag=tag, coe="i") assert isinstance(output, pd.DataFrame) - assert output.shape == (14294, 12) + assert output.shape == (14338, 12) columns = list(output.columns) assert columns[:6] == ["x", "y", "i_1", "i_2", "dist_1", "dist_2"] assert columns[6:] == ["head_1", "head_2", "vel_1", "vel_2", "z_X", "z_M"] @@ -214,10 +214,10 @@ def test_x2sys_cross_region_interpolation_numpoints(): ) assert isinstance(output, pd.DataFrame) - assert output.shape == (3867, 12) + assert output.shape == (3882, 12) # Check crossover errors (z_X) and mean value of observables (z_M) - npt.assert_allclose(output.z_X.mean(), -139.2, rtol=1e-4) - npt.assert_allclose(output.z_M.mean(), -2890.465813) + npt.assert_allclose(output.z_X.mean(), -138.66, rtol=1e-4) + npt.assert_allclose(output.z_M.mean(), -2896.875915) @pytest.mark.usefixtures("mock_x2sys_home") @@ -231,7 +231,7 @@ def test_x2sys_cross_trackvalues(): output = x2sys_cross(tracks=["@tut_ship.xyz"], tag=tag, trackvalues=True) assert isinstance(output, pd.DataFrame) - assert output.shape == (14294, 12) + assert output.shape == (14338, 12) # Check mean of track 1 values (z_1) and track 2 values (z_2) - npt.assert_allclose(output.z_1.mean(), -2420.569767) - npt.assert_allclose(output.z_2.mean(), -2400.357549) + npt.assert_allclose(output.z_1.mean(), -2422.418556) + npt.assert_allclose(output.z_2.mean(), -2402.268364)