-
Notifications
You must be signed in to change notification settings - Fork 301
Add points/bounds formatting method and class, handling datetimes #6978
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ESadek-MO
merged 8 commits into
SciTools:main
from
stephenworsley:date_strings_from_units
Mar 16, 2026
+159
−0
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ea634c7
add points/bounds formatting class
stephenworsley e858cc1
add tests
stephenworsley 1e80913
add test, fix boundless handling
stephenworsley d4d8f7e
ruff fix
stephenworsley b830a7c
print None bounds, expand docstring
stephenworsley d916611
whatsnew and review comments
stephenworsley 28c4d7a
Update docs/src/whatsnew/latest.rst
stephenworsley 895483d
change __repr__ to __str__
stephenworsley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,83 @@ | ||
| # Copyright Iris contributors | ||
| # | ||
| # This file is part of Iris and is released under the BSD license. | ||
| # See LICENSE in the root of the repository for full licensing details. | ||
| """Unit tests for the :class:`iris.coords.PointBoundString class.""" | ||
|
|
||
| from cf_units import Unit | ||
| import dask.array as da | ||
| import numpy as np | ||
|
|
||
| from iris._lazy_data import is_lazy_data | ||
| from iris.coords import AuxCoord, PointBoundStrings | ||
| from iris.tests._shared_utils import assert_array_equal | ||
|
|
||
|
|
||
| def test_PointBoundStrings_lazy(): | ||
| lazy_points = da.arange(5, dtype=np.float64) | ||
| lazy_bounds = da.arange(10, dtype=np.float64).reshape([5, 2]) | ||
|
|
||
| lazy_coord = AuxCoord(lazy_points, bounds=lazy_bounds, standard_name="latitude") | ||
|
|
||
| fmt = ".0f" | ||
| pbs = lazy_coord.as_string_arrays(fmt) | ||
| assert is_lazy_data(pbs._core_bounds) | ||
| assert pbs._bounds is None | ||
|
|
||
| expected_bounds = "[['0' '1']\n ['2' '3']\n ['4' '5']\n ['6' '7']\n ['8' '9']]" | ||
| assert np.array2string(pbs.bounds) == expected_bounds | ||
| assert pbs._core_bounds is None | ||
| assert pbs._bounds is pbs.bounds | ||
| assert is_lazy_data(pbs._core_points) | ||
| assert pbs._points is None | ||
|
|
||
| assert lazy_coord.has_lazy_points() | ||
| assert lazy_coord.has_lazy_bounds() | ||
|
|
||
|
|
||
| def test_PointBoundStrings_no_bounds(): | ||
| points = np.arange(5, dtype=np.float64) | ||
|
|
||
| coord = AuxCoord(points, standard_name="latitude") | ||
| pbs = coord.as_string_arrays() | ||
|
|
||
| expected_output = "Points:\n['0.0' '1.0' '2.0' '3.0' '4.0']\nBounds:\nNone" | ||
| assert str(pbs) == expected_output | ||
|
|
||
| expected_points = np.array(["0.0", "1.0", "2.0", "3.0", "4.0"]) | ||
| assert_array_equal(pbs.points, expected_points) | ||
|
|
||
| assert pbs.bounds is None | ||
|
|
||
|
|
||
| def test_PointBoundStrings_time_coord(): | ||
| time_unit = Unit("days since epoch") | ||
| points = np.arange(5) | ||
| bounds = np.arange(10).reshape([5, 2]) | ||
|
|
||
| pbs_unformatted = PointBoundStrings(points, bounds, time_unit) | ||
| expected_unformatted = ( | ||
| "Points:\n" | ||
| "['1970-01-01 00:00:00' '1970-01-02 00:00:00' '1970-01-03 00:00:00'\n" | ||
| " '1970-01-04 00:00:00' '1970-01-05 00:00:00']\n" | ||
| "Bounds:\n" | ||
| "[['1970-01-01 00:00:00' '1970-01-02 00:00:00']\n" | ||
| " ['1970-01-03 00:00:00' '1970-01-04 00:00:00']\n" | ||
| " ['1970-01-05 00:00:00' '1970-01-06 00:00:00']\n" | ||
| " ['1970-01-07 00:00:00' '1970-01-08 00:00:00']\n" | ||
| " ['1970-01-09 00:00:00' '1970-01-10 00:00:00']]" | ||
| ) | ||
| assert str(pbs_unformatted) == expected_unformatted | ||
| fmt = "%Y-%m-%d" | ||
| pbs_formatted = PointBoundStrings(points, bounds, time_unit, fmt=fmt) | ||
| expected_formatted = ( | ||
| "Points:\n" | ||
| "['1970-01-01' '1970-01-02' '1970-01-03' '1970-01-04' '1970-01-05']\n" | ||
| "Bounds:\n" | ||
| "[['1970-01-01' '1970-01-02']\n" | ||
| " ['1970-01-03' '1970-01-04']\n" | ||
| " ['1970-01-05' '1970-01-06']\n" | ||
| " ['1970-01-07' '1970-01-08']\n" | ||
| " ['1970-01-09' '1970-01-10']]" | ||
| ) | ||
| assert str(pbs_formatted) == expected_formatted |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.