Skip to content
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

Add tests for grib idx & reinflate #528

Merged
merged 9 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions tests/test__grib_idx.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""

import copy
import re
import unittest
Expand Down Expand Up @@ -247,7 +248,13 @@ def test_build_idx_grib_mapping(self):
f"{mapping_fname}.idx_grib_mapping.parquet",
)
# Build the mapping from idx to cfgrib metadata and assert it matches the fixture
pd.testing.assert_frame_equal(mapping, pd.read_parquet(test_path))
expected = pd.read_parquet(test_path)
pd.testing.assert_frame_equal(
mapping,
expected.assign(
step=lambda x: x.step.astype("timedelta64[ns]")
),
)

# parse the idx files for 20231104 and compare the mapped result to the direct indexed result
test_name = fnames["20231104"]
Expand Down Expand Up @@ -284,6 +291,10 @@ def test_build_idx_grib_mapping(self):
)
expected = pd.read_parquet(kindex_test_path)

expected = expected.assign(
step=lambda x: x.step.astype("timedelta64[ns]")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@martindurant These errors in the CI system are really strange... These typically only happen when using an old version of numpy/pandas that has a different default time type.
The last one, the sync error... that seems like maybe I need to convert from unittest subtest to pytest?

)

expected = expected.set_index(
["varname", "typeOfLevel", "stepType", "step", "level"]
).sort_index()
Expand Down Expand Up @@ -382,7 +393,13 @@ def test_kerchunk_indexing(self):
TEST_DATE,
f"{fname}.kindex.parquet",
)
pd.testing.assert_frame_equal(kindex, pd.read_parquet(test_path))
expected = pd.read_parquet(test_path)
pd.testing.assert_frame_equal(
kindex,
expected.assign(
step=lambda x: x.step.astype("timedelta64[ns]")
),
)

@unittest.skip("TODO")
def test_extract_dataset_chunk_index(self):
Expand Down Expand Up @@ -428,7 +445,9 @@ def _test_index_extraction(self, sample_prefix: str):
THIS_DIR, "grib_idx_fixtures", sample_prefix, "kerchunk_index.parquet"
)
expected = pd.read_parquet(test_path)
pd.testing.assert_frame_equal(k_index, expected)
pd.testing.assert_frame_equal(
k_index, expected.assign(step=lambda x: x.step.astype("timedelta64[ns]"))
)

def test_strip_datavar_chunks(self):
for sample_prefix, pre, post in [
Expand Down Expand Up @@ -587,7 +606,7 @@ def _reinflate_grib_store(
with self.subTest(node_path=node.path):

match aggregation:
case (AggregationType.HORIZON | AggregationType.BEST_AVAILABLE):
case AggregationType.HORIZON | AggregationType.BEST_AVAILABLE:

self.assertEqual(node.time.dims, node.valid_time.dims)
self.assertEqual(node.time.dims, node.step.dims)
Expand Down
1 change: 1 addition & 0 deletions tests/test_xarray_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
format="NETCDF3_CLASSIC"
)


# Add parameterize test for storage formats (.json, .parquet)
def test_reference_netcdf(m):
m.pipe("data.nc3", bdata)
Expand Down
Loading