Skip to content

Commit

Permalink
Merge branch 'main' into docs/630-docs-readability
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvothecoder authored Apr 10, 2024
2 parents 5373c43 + 1f4d22a commit 03e271e
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 588 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,11 @@ jobs:
pytest
- name: Upload Coverage Report
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
file: "tests_coverage_reports/coverage.xml"
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}

# `build-result` is a workaround to skipped matrix jobs in `build` not being considered "successful",
# which can block PR merges if matrix jobs are required status checks.
Expand Down
1 change: 0 additions & 1 deletion conda-env/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ dependencies:
- cf_xarray >=0.7.3 # Constrained because https://github.com/xarray-contrib/cf-xarray/issues/467
- cftime
- dask
- lxml # TODO: Remove this in v0.7.0 once cdml/XML support is dropped
- netcdf4
- numpy >=1.23.0 # This version of numpy includes support for Python 3.11.
- pandas
Expand Down
1 change: 0 additions & 1 deletion conda-env/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ dependencies:
- cf_xarray >=0.7.3 # Constrained because https://github.com/xarray-contrib/cf-xarray/issues/467
- cftime
- dask
- lxml # TODO: Remove this in v0.7.0 once cdml/XML support is dropped
- netcdf4
- numpy >=1.23.0 # This version of numpy includes support for Python 3.11.
- pandas
Expand Down
117 changes: 0 additions & 117 deletions tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import numpy as np
import pytest
import xarray as xr
from lxml import etree

from tests.fixtures import generate_dataset
from xcdat._logger import _setup_custom_logger
Expand Down Expand Up @@ -77,9 +76,6 @@ def test_skips_adding_bounds(self):
ds = generate_dataset(decode_times=True, cf_compliant=True, has_bounds=False)
ds.to_netcdf(self.file_path)

result = open_dataset(self.file_path, add_bounds=False)
assert result.identical(ds)

result = open_dataset(self.file_path, add_bounds=None)
assert result.identical(ds)

Expand Down Expand Up @@ -324,48 +320,6 @@ def test_keeps_specified_var_and_preserves_bounds(self):

assert result.identical(expected)

def test_raises_deprecation_warning_when_passing_add_bounds_true(self):
ds_no_bounds = generate_dataset(
decode_times=True, cf_compliant=True, has_bounds=False
)
ds_no_bounds.to_netcdf(self.file_path)

with warnings.catch_warnings(record=True) as w:
result = open_dataset(self.file_path, add_bounds=True)

assert len(w) == 1
assert issubclass(w[0].category, DeprecationWarning)
assert str(w[0].message) == (
"`add_bounds=True` will be deprecated after v0.6.0. Please use a list "
"of axis strings instead (e.g., `add_bounds=['X', 'Y']`)."
)

expected = generate_dataset(
decode_times=True, cf_compliant=True, has_bounds=True
)
expected = expected.drop_vars("time_bnds")
del expected["time"].attrs["bounds"]

assert result.identical(expected)

def test_raises_deprecation_warning_when_passing_add_bounds_false(self):
ds_no_bounds = generate_dataset(
decode_times=True, cf_compliant=True, has_bounds=False
)
ds_no_bounds.to_netcdf(self.file_path)

with warnings.catch_warnings(record=True) as w:
result = open_dataset(self.file_path, add_bounds=False)

assert len(w) == 1
assert issubclass(w[0].category, DeprecationWarning)
assert str(w[0].message) == (
"`add_bounds=False` will be deprecated after v0.6.0. Please use "
"`add_bounds=None` instead."
)

assert result.identical(ds_no_bounds)


class TestOpenMfDataset:
@pytest.fixture(autouse=True)
Expand Down Expand Up @@ -410,80 +364,9 @@ def test_skips_adding_bounds(self):
ds = generate_dataset(decode_times=True, cf_compliant=True, has_bounds=False)
ds.to_netcdf(self.file_path1)

result = open_mfdataset(self.file_path1, add_bounds=False)
assert result.identical(ds)

result = open_mfdataset(self.file_path1, add_bounds=None)
assert result.identical(ds)

def test_raises_error_if_xml_does_not_have_root_directory_attr(self):
ds1 = generate_dataset(decode_times=False, cf_compliant=False, has_bounds=True)
ds1.to_netcdf(self.file_path1)
ds2 = generate_dataset(decode_times=False, cf_compliant=False, has_bounds=True)
ds2 = ds2.rename_vars({"ts": "tas"})
ds2.to_netcdf(self.file_path2)

# Create the XML file
xml_path = f"{self.dir}/datasets.xml"
page = etree.Element("dataset")
doc = etree.ElementTree(page)
doc.write(xml_path, xml_declaration=True, encoding="utf-16")

with pytest.raises(KeyError):
open_mfdataset(xml_path, decode_times=True)

def test_opens_datasets_from_xml_using_str_path(self):
ds1 = generate_dataset(decode_times=False, cf_compliant=False, has_bounds=True)
ds1.to_netcdf(self.file_path1)
ds2 = generate_dataset(decode_times=False, cf_compliant=False, has_bounds=True)
ds2 = ds2.rename_vars({"ts": "tas"})
ds2.to_netcdf(self.file_path2)

# Create the XML file
xml_path = f"{self.dir}/datasets.xml"
page = etree.Element("dataset", directory=str(self.dir))
doc = etree.ElementTree(page)
doc.write(xml_path, xml_declaration=True, encoding="utf-16")

result = open_mfdataset(xml_path, decode_times=True)
expected = ds1.merge(ds2)

result.identical(expected)

def test_opens_datasets_from_xml_raises_deprecation_warning(self):
ds1 = generate_dataset(decode_times=False, cf_compliant=False, has_bounds=True)
ds1.to_netcdf(self.file_path1)
ds2 = generate_dataset(decode_times=False, cf_compliant=False, has_bounds=True)
ds2 = ds2.rename_vars({"ts": "tas"})
ds2.to_netcdf(self.file_path2)

# Create the XML file
xml_path = f"{self.dir}/datasets.xml"
page = etree.Element("dataset", directory=str(self.dir))
doc = etree.ElementTree(page)
doc.write(xml_path, xml_declaration=True, encoding="utf-16")

with pytest.warns(DeprecationWarning):
open_mfdataset(xml_path, decode_times=True)

def test_opens_datasets_from_xml_using_pathlib_path(self):
ds1 = generate_dataset(decode_times=False, cf_compliant=False, has_bounds=True)
ds1.to_netcdf(self.file_path1)
ds2 = generate_dataset(decode_times=False, cf_compliant=False, has_bounds=True)
ds2 = ds2.rename_vars({"ts": "tas"})
ds2.to_netcdf(self.file_path2)

# Create the XML file
xml_path = self.dir / "datasets.xml"
page = etree.Element("dataset", directory=str(self.dir))
doc = etree.ElementTree(page)
doc.write(xml_path, xml_declaration=True, encoding="utf-16")

result = open_mfdataset(xml_path, decode_times=True)
expected = ds1.merge(ds2)

result.identical(expected)

def test_raises_error_if_directory_has_no_netcdf_files(self):
with pytest.raises(ValueError):
open_mfdataset(str(self.dir), decode_times=True)
Expand Down
Loading

0 comments on commit 03e271e

Please sign in to comment.