Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test, refactor, and deprecate extract_time_period (#243)
* test, refactor, and deprecate extract_time_period * changlog * update deprecation warning
- Loading branch information
Showing
3 changed files
with
78 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import numpy as np | ||
import pytest | ||
|
||
from mesmer.utils.select import extract_time_period | ||
|
||
|
||
def test_extract_time_period_deprecation(): | ||
|
||
time = np.arange(1950, 2050) | ||
|
||
data = np.linspace(0, 1, time.size) | ||
|
||
with pytest.warns(FutureWarning, match="`extract_time_period` is deprecated"): | ||
extract_time_period(data, time, 1955, 2005) | ||
|
||
|
||
@pytest.mark.filterwarnings("ignore:`extract_time_period` is deprecated") | ||
def test_extract_time_period_1D(): | ||
|
||
time = np.arange(1950, 2050) | ||
|
||
data = np.linspace(0, 1, time.size) | ||
|
||
result_data, result_time = extract_time_period(data, time, 1955, 2005) | ||
|
||
expected_data = data[5 : 5 + 50 + 1] | ||
expected_time = np.arange(1955, 2005 + 1) | ||
|
||
np.testing.assert_equal(result_data, expected_data) | ||
np.testing.assert_equal(result_time, expected_time) | ||
|
||
|
||
@pytest.mark.filterwarnings("ignore:`extract_time_period` is deprecated") | ||
def test_extract_time_period_2D(): | ||
|
||
time = np.arange(1900, 2000) | ||
|
||
data = np.arange(3 * time.size).reshape(3, -1) | ||
|
||
result_data, result_time = extract_time_period(data, time, 1911, 1995) | ||
|
||
expected_data = data[:, 11 : 95 + 1] | ||
expected_time = np.arange(1911, 1995 + 1) | ||
|
||
np.testing.assert_equal(result_data, expected_data) | ||
np.testing.assert_equal(result_time, expected_time) | ||
|
||
|
||
@pytest.mark.filterwarnings("ignore:`extract_time_period` is deprecated") | ||
def test_extract_time_period_3D(): | ||
|
||
time = np.arange(1900, 2000) | ||
|
||
# (run, time, gridpoint) | ||
data = np.arange(3 * 5 * time.size).reshape(3, -1, 5) | ||
|
||
result_data, result_time = extract_time_period(data, time, 1911, 1995) | ||
|
||
expected_data = data[:, 11 : 95 + 1, :] | ||
expected_time = np.arange(1911, 1995 + 1) | ||
|
||
np.testing.assert_equal(result_data, expected_data) | ||
np.testing.assert_equal(result_time, expected_time) |