-
Notifications
You must be signed in to change notification settings - Fork 41
Let an author keep a column to themselves #993
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
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1686,6 +1686,64 @@ def _forge(frame: pd.DataFrame, path, documents: str) -> None: | |
|
|
||
|
|
||
| @pytest.mark.skipif(pyarrow is None, reason="pyarrow is not installed") | ||
| class TestPrivateColumns: | ||
|
Comment on lines
1688
to
+1689
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When PyArrow is not installed, this insertion attaches the existing Useful? React with 👍 / 👎. |
||
| """A column an author kept for themselves is read by nothing.""" | ||
|
|
||
| def test_a_bare_table(self, tmp_path): | ||
| """A note on how something was deployed stays in the file.""" | ||
| path = tmp_path / "picks.csv" | ||
| path.write_text( | ||
| "id,group,distance_start,distance_end,_crew\n" | ||
| "r1,noise,10.0,60.0,north crew\n" | ||
| ) | ||
| loaded = dc.annotations(path, dims=DIMS) | ||
| assert "_crew" not in loaded.io.to_dataframe().columns | ||
| assert loaded[0].group == "noise" | ||
|
|
||
| def test_a_saved_set(self, regions, tmp_path): | ||
| """One added to a written table changes nothing about the set.""" | ||
| directory = regions.io.save(tmp_path / "picks") | ||
| table = directory / "annotations.csv" | ||
| header, *rows = table.read_text().splitlines() | ||
| written = [f"{header},_crew", *[f"{row},north crew" for row in rows]] | ||
| table.write_text("\n".join(written) + "\n") | ||
| assert dc.annotations(directory) == regions | ||
|
|
||
| def test_nothing_reads_what_it_holds(self, tmp_path): | ||
| """A declaration a private column cannot meet is not checked.""" | ||
| directory = tmp_path / "picks" | ||
| directory.mkdir() | ||
| (directory / "annotations.csv").write_text( | ||
| "id,distance,_count\nr1,1.0,not a number\n" | ||
| ) | ||
| (directory / "attrs.yaml").write_text( | ||
| yaml.safe_dump( | ||
| { | ||
| "object_type": "AnnotationSetAttrs", | ||
| "dims": list(DIMS), | ||
| "columns": {"_count": {"dtype": "Int64"}}, | ||
| } | ||
| ) | ||
| ) | ||
| assert len(dc.annotations(directory)) == 1 | ||
|
|
||
| def test_a_table_of_only_private_columns(self, tmp_path): | ||
| """Rows no column of the set states are refused, not lost.""" | ||
| path = tmp_path / "picks.csv" | ||
| path.write_text("_crew\nnorth crew\n") | ||
| with pytest.raises(InvalidAnnotationError, match="read by nothing"): | ||
| dc.annotations(path, dims=DIMS) | ||
|
|
||
| def test_vertices(self, with_vertices, tmp_path): | ||
| """Vertices are a table like any other, so they take one too.""" | ||
| directory = with_vertices.io.save(tmp_path / "picks") | ||
| table = directory / "vertices.csv" | ||
| header, *rows = table.read_text().splitlines() | ||
| written = [f"{header},_source", *[f"{row},drawing 4" for row in rows]] | ||
| table.write_text("\n".join(written) + "\n") | ||
| assert dc.annotations(directory) == with_vertices | ||
|
|
||
|
|
||
| class TestParquet: | ||
| """The same tables, with their types kept, for a set too big to want text.""" | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When an annotation Parquet file marks an underscore-prefixed column in
dascore:documents,read_parquet()parses and validates that column's JSON before_kept_columns()removes it. Consequently, malformed or otherwise non-DASCore content in a private column still raisesParameterError, unlike the CSV path and contrary to the rule that private-column contents are never interpreted. The private columns need to be excluded beforeread_parquet()performs document-column decoding.Useful? React with 👍 / 👎.