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

More than one source in a dataset #17

Merged
merged 2 commits into from
Feb 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ unreleased
----------
* Add the ``da.pr.set()`` and ``ds.pr.set()`` functions for overwriting / infilling /
extending data.
* Allow for more than one source in a single Dataset / DataArray.

0.3.1
-----
Expand Down
1 change: 0 additions & 1 deletion docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ Attributes
Dataset.pr.comment
Dataset.pr.institution
Dataset.pr.history
Dataset.pr.source

.. _dsmeth:

Expand Down
1 change: 0 additions & 1 deletion docs/data_format_details.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ category-set (for example, ``animal (FAOSTAT)``).

Additional rules:

* The size of the ``source`` dimension must be exactly 1.
* The valid values for the ``provenance`` are ``measured``, ``projected``, and
``derived``.

Expand Down
2 changes: 1 addition & 1 deletion docs/data_format_examples.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@
" \"scenario (FAOSTAT)\": np.array([\"highpop\", \"lowpop\"]),\n",
" \"provenance\": np.array([\"projected\"]),\n",
" \"model\": np.array([\"FANCYFAO\"]),\n",
" \"source\": np.array([\"RAND2020\"]),\n",
" \"source\": np.array([\"RAND2020\", \"RAND2021\"]),\n",
"}\n",
"\n",
"opulent = xr.Dataset(\n",
Expand Down
4 changes: 0 additions & 4 deletions primap2/_data_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,6 @@ def ensure_valid_dimensions(ds: xr.Dataset):
f" sec_cats."
)

if ds.dims["source"] != 1:
logger.error("Exactly one source required per data set.")
raise ValueError("Exactly one source required")

for dim in required_indirect_dims.union(optional_indirect_dims):
if dim in ds.attrs:
split_dim_name(ds.attrs[dim])
9 changes: 0 additions & 9 deletions primap2/_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,3 @@ def history(self) -> str:
@history.setter
def history(self, value: str):
self._ds.attrs["history"] = value

@property
def source(self) -> str:
"""a short identifier for the source of the data"""
return self._ds["source"].item()

@source.setter
def source(self, value: str):
self._ds["source"] = [value]
Binary file modified primap2/tests/data/test_sum_skip_allna_inhomogeneous_result.nc
Binary file not shown.
2 changes: 1 addition & 1 deletion primap2/tests/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def opulent_ds():
"scenario (FAOSTAT)": np.array(["highpop", "lowpop"]),
"provenance": np.array(["projected"]),
"model": np.array(["FANCYFAO"]),
"source": np.array(["RAND2020"]),
"source": np.array(["RAND2020", "RAND2021"]),
}

# seed the rng with a constant to achieve predictable "randomness"
Expand Down
21 changes: 2 additions & 19 deletions primap2/tests/test_data_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ def test_something_else_entirely(caplog):
assert "object is not an xarray Dataset." in caplog.text


def test_valid_ds_pass(minimal_ds, opulent_ds, caplog):
def test_valid_ds_pass(any_ds, caplog):
caplog.set_level(logging.INFO)
minimal_ds.pr.ensure_valid()
opulent_ds.pr.ensure_valid()
any_ds.pr.ensure_valid()
assert not caplog.records


Expand Down Expand Up @@ -109,22 +108,6 @@ def test_wrong_dimension_key(minimal_ds, caplog):
assert "'asdf' not in the format 'dim (category_set)'." in caplog.text


def test_not_one_source(minimal_ds: xr.Dataset, caplog):
ds = minimal_ds.loc[{"source": "RAND2020"}]
ds["source"] = []
with pytest.raises(ValueError, match=r"Exactly one source required"):
ds.pr.ensure_valid()
assert "ERROR" in caplog.text
assert "Exactly one source required per data set." in caplog.text

caplog.clear()
ds["source"] = ["a", "b"]
with pytest.raises(ValueError, match=r"Exactly one source required"):
ds.pr.ensure_valid()
assert "ERROR" in caplog.text
assert "Exactly one source required per data set." in caplog.text


def test_missing_sec_cat(minimal_ds, caplog):
minimal_ds.attrs["sec_cats"] = ["missing"]
with pytest.raises(ValueError, match="Secondary category 'missing' not in dims"):
Expand Down
3 changes: 0 additions & 3 deletions primap2/tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ def test_metadata_properties(opulent_ds):
assert ds.pr.history == (
"2021-01-14 14:50 data invented\n" "2021-01-14 14:51 additional processing step"
)
assert ds.pr.source == "RAND2020"

ds.pr.references = "references"
assert ds.pr.references == "references"
Expand All @@ -28,5 +27,3 @@ def test_metadata_properties(opulent_ds):
assert ds.pr.institution == "institution"
ds.pr.history = "history"
assert ds.pr.history == "history"
ds.pr.source = "source"
assert ds.pr.source == "source"