anon-iclr-submission/benchname-bug-localization huggingface dataset:
Repository: ocr-d/core
Issue: resmgr: strange datetime interpretation of name

If I add an entry…
```yaml
ocrd-eynollah-segment:
  - url: https://qurator-data.de/eynollah/2022-04-05/models_eynollah_renamed.tar.gz
    name: 2022-04-05
    description: models for eynollah
    type: tarball
    path_in_archive: 'models_eynollah'
    size: 1889719626
```
…then this is what I get…
```
06:59:37.278 ERROR ocrd.resource_manager - [ocrd-eynollah-segment.0.name] datetime.date(2022, 4, 5) is not of type 'string'
```

I have to prefix the name with some other string to get it working.

Changed files:
ocrd/ocrd/resource_manager.py, tests/test_resource_manager.py

diff --git a/ocrd/ocrd/resource_manager.py b/ocrd/ocrd/resource_manager.py
index 4720cb54..0b66f523 100644
--- a/ocrd/ocrd/resource_manager.py
+++ b/ocrd/ocrd/resource_manager.py
@@ -9,6 +9,12 @@ from urllib.parse import urlparse, unquote
 import requests
 from yaml import safe_load, safe_dump
 
+# https://github.com/OCR-D/core/issues/867
+# https://stackoverflow.com/questions/50900727/skip-converting-entities-while-loading-a-yaml-string-using-pyyaml
+import yaml.constructor
+yaml.constructor.SafeConstructor.yaml_constructors[u'tag:yaml.org,2002:timestamp'] = \\
+    yaml.constructor.SafeConstructor.yaml_constructors[u'tag:yaml.org,2002:str']
+
 from ocrd_validators import OcrdResourceListValidator
 from ocrd_utils import getLogger
 from ocrd_utils.os import get_processor_resource_types, list_all_resources, pushd_popd
diff --git a/tests/test_resource_manager.py b/tests/test_resource_manager.py
index 21cd4520..ea30c6d2 100644
--- a/tests/test_resource_manager.py
+++ b/tests/test_resource_manager.py
@@ -104,5 +104,21 @@ def test_default_resource_dir(tmp_path):
     assert mgr.xdg_config_home != mgr.xdg_data_home
     assert mgr.default_resource_dir == str(mgr.xdg_data_home / 'ocrd-resources')
 
+def test_date_as_string(tmp_path):
+    mgr = OcrdResourceManager(xdg_data_home=tmp_path)
+    test_list = tmp_path / 'test-list.yml'
+    with open(test_list, 'w', encoding='utf-8') as fout:
+        fout.write("""\\
+    ocrd-eynollah-segment:
+      - url: https://qurator-data.de/eynollah/2022-04-05/models_eynollah_renamed.tar.gz
+        name: 2022-04-05
+        description: models for eynollah
+        type: tarball
+        path_in_archive: 'models_eynollah'
+        size: 1889719626
+        """)
+    mgr.load_resource_list(test_list)
+    mgr.list_available(executable='ocrd-eynollah-segment')
+
 if __name__ == "__main__":
     main(__file__)
Repository: ocr-d/core
Issue: ocrd workspace remove: recursive is not passed

When running

    ocrd workspace -d bucher1806_florae remove-group -fr GT

I get
```
Exception: fileGrp GT is not empty and recursive wasn't set
```

The culprit is here:
https://github.com/OCR-D/core/blob/f9c2b6c825186d6021d28b2deb9616f645ccfb68/ocrd/ocrd/workspace.py#L248



Changed files:
ocrd/ocrd/workspace.py

diff --git a/ocrd/ocrd/workspace.py b/ocrd/ocrd/workspace.py
index f6f82aae..3a578323 100644
--- a/ocrd/ocrd/workspace.py
+++ b/ocrd/ocrd/workspace.py
@@ -245,7 +245,7 @@ class Workspace():
                     if f_dir:
                         file_dirs.append(f_dir)
 
-        self.mets.remove_file_group(USE, force=force)
+        self.mets.remove_file_group(USE, force=force, recursive=recursive)
 
         # PLEASE NOTE: this only removes directories in the workspace if they are empty
         # and named after the fileGrp which is a convention in OCR-D.
Repository: ocr-d/core
Issue: ocrd zip bag: cannot run without in-place

```
ocrd zip bag -i bucher1806_florae
Error: Missing option '-I' / '--in-place'.
```

This happens with `click>=8.1.0`, which apparently became more strict.

The culprit is here: https://github.com/OCR-D/core/blob/6d359e73693df18360fe0f47383377a95e99a934/ocrd/ocrd/cli/zip.py#L42

(the `required=True` is wrong)

Changed files:
ocrd/ocrd/cli/zip.py

diff --git a/ocrd/ocrd/cli/zip.py b/ocrd/ocrd/cli/zip.py
index 50776e9c..eebd49ac 100644
--- a/ocrd/ocrd/cli/zip.py
+++ b/ocrd/ocrd/cli/zip.py
@@ -39,7 +39,7 @@ def zip_cli():
               help='Basename of the METS file.',
               show_default=True)
 @click.option('-i', '--identifier', '--id', help="Ocrd-Identifier", required=True)
-@click.option('-I', '--in-place', help="Replace workspace with bag (like bagit.py does)", required=True, is_flag=True)
+@click.option('-I', '--in-place', help="Replace workspace with bag (like bagit.py does)", is_flag=True)
 @click.option('-D', '--manifestation-depth', help="Ocrd-Manifestation-Depth", type=click.Choice(['full', 'partial']), default='partial')
 @click.option('-m', '--mets', help="location of mets.xml in the bag's data dir", default="mets.xml")
 @click.option('-b', '--base-version-checksum', help="Ocrd-Base-Version-Checksum")
Repository: ocr-d/core
Issue: workspace remove-group fails with FNFE

I happen to have a METS with files not under the conventional fileGrp directory. Upon trying `ocrd workspace remove-group -fr GRP` I then get:
```
  File "ocrd/workspace.py", line 241, in remove_file_group
    if Path(file_dir).is_dir() and not listdir(file_dir):
FileNotFoundError: [Errno 2] No such file or directory: ''
```

Digging into the code…
https://github.com/OCR-D/core/blob/061bae37f79aaac5aea64cf9afb8e1429b8243f5/ocrd/ocrd/workspace.py#L236-L253

…I believe the culprit is that `dirname` can give you empty strings when you have no directory component (unlike some `Path` functions, which will yield `.`). So the simplest fix would be to just add an extra check `file_dir and` in L252.


Changed files:
ocrd/ocrd/workspace.py, tests/test_workspace.py

diff --git a/ocrd/ocrd/workspace.py b/ocrd/ocrd/workspace.py
index 0b69f2a5..7bfb38a2 100644
--- a/ocrd/ocrd/workspace.py
+++ b/ocrd/ocrd/workspace.py
@@ -238,7 +238,9 @@ class Workspace():
             for f in self.mets.find_files(fileGrp=USE):
                 self.remove_file(f, force=force, keep_file=keep_files, page_recursive=page_recursive, page_same_group=page_same_group)
                 if f.local_filename:
-                    file_dirs.append(path.dirname(f.local_filename))
+                    f_dir = path.dirname(f.local_filename)
+                    if f_dir:
+                        file_dirs.append(f_dir)
 
         self.mets.remove_file_group(USE, force=force)
 
diff --git a/tests/test_workspace.py b/tests/test_workspace.py
index b6202090..b5516afa 100644
--- a/tests/test_workspace.py
+++ b/tests/test_workspace.py
@@ -210,6 +210,16 @@ class TestWorkspace(TestCase):
             workspace.remove_file_group('OCR-D-IMG', recursive=True)
             self.assertFalse(exists(join(tempdir, 'OCR-D-IMG')))
 
+    def test_remove_file_group_flat(self):
+        """
+        https://github.com/OCR-D/core/issues/728
+        """
+        with pushd_popd(tempdir=True) as tempdir:
+            workspace = self.resolver.workspace_from_nothing(directory=tempdir)
+            f1 = Path(workspace.add_file('FOO', ID='foo', mimetype='foo/bar', local_filename='file.ext', content='foo', pageId=None).url)
+            assert f1.exists()
+            workspace.remove_file_group('FOO', recursive=True)
+
     def test_remove_file_page_recursive(self):
         with copy_of_directory(assets.path_to('kant_aufklaerung_1784-complex/data')) as tempdir:
             with pushd_popd(tempdir):
Repository: ocr-d/core
Issue: ocrd workspace find --download does not use correct workspace prefix

There is a flaw in the workspace directory resolution of the CLI:

    ocrd workspace -d Brsfded_39946221X-18920413 find -G ORIGINAL --download

This will:

- change remote links in `Brsfded_39946221X-18920413/mets.xml` to local ones, now pointing to `ORIGINAL/*`
- download the files under `Brsfded_39946221X-18920413/Brsfded_39946221X-18920413/ORIGINAL` (one level too deep)


Changed files:
ocrd/ocrd/cli/workspace.py

diff --git a/ocrd/ocrd/cli/workspace.py b/ocrd/ocrd/cli/workspace.py
index bd4011c2..908f55b3 100644
--- a/ocrd/ocrd/cli/workspace.py
+++ b/ocrd/ocrd/cli/workspace.py
@@ -31,6 +31,7 @@ class WorkspaceCtx():
                 raise ValueError("--mets is an http(s) URL but no --directory was given")
             directory = dirname(abspath(mets_url)) or getcwd()
         elif directory and not mets_url:
+            directory = abspath(directory)
             mets_url = join(directory, mets_basename)
         else:
             directory = getcwd()
Repository: ocr-d/core
Issue: bagger spill regression from 1f0ce7dc

Our `ocrd zip spill` is currently broken: it now has an option `dest` (no more `directory`) but the function has no parameter of that name. So click will always give you:

```TypeError: spill() got an unexpected keyword argument 'dest'```

Changed files:
ocrd/ocrd/cli/zip.py

diff --git a/ocrd/ocrd/cli/zip.py b/ocrd/ocrd/cli/zip.py
index b91aaf4e..561a4206 100644
--- a/ocrd/ocrd/cli/zip.py
+++ b/ocrd/ocrd/cli/zip.py
@@ -68,7 +68,7 @@ def bag(directory, mets_basename, dest, identifier, in_place, manifestation_dept
               help='Workspace folder location.',
               show_default=True)
 @click.argument('src', type=click.Path(dir_okay=False, readable=True, resolve_path=True), required=True)
-def spill(directory, src):
+def spill(dest, src):
     """
     Spill/unpack OCRD-ZIP bag at SRC to DEST
Repository: ocr-d/core
Issue: ocrd workspace init with metsflag creates 2 mets files

**Expected Bahavior**

When one issues the follwing cli command 

`ocr workspace -M foo.xml init .`

only one Metsfile with name `foo.xml`shall be created.


**Actual Behaviour**

When one issues the follwing cli command 

`ocr workspace -M foo.xml init .`

2 files are created in the new workspace, one called `foo.xml` and a `mets.xml`, both having the same content.

**Version**
ocrd==2.2.2

**Files**

[ocrd-workspace-init-files.zip](https://github.com/OCR-D/core/files/4086137/ocrd-workspace-init-files.zip)




Changed files:
tests/cli/test_workspace.py, ocrd/ocrd/resolver.py

diff --git a/ocrd/ocrd/resolver.py b/ocrd/ocrd/resolver.py
index 63fdd396..5c4aad80 100644
--- a/ocrd/ocrd/resolver.py
+++ b/ocrd/ocrd/resolver.py
@@ -175,4 +175,4 @@ class Resolver():
         log.info("Writing METS to %s", mets_path)
         mets_path.write_bytes(mets.to_xml(xmllint=True))
 
-        return Workspace(self, directory, mets)
+        return Workspace(self, directory, mets, mets_basename=mets_basename)
diff --git a/tests/cli/test_workspace.py b/tests/cli/test_workspace.py
index adda41f2..923c3bba 100644
--- a/tests/cli/test_workspace.py
+++ b/tests/cli/test_workspace.py
@@ -264,5 +264,13 @@ class TestCli(TestCase):
                 self.assertEqual(full_vs_copied.left_only, [])
                 self.assertEqual(full_vs_copied.right_only, [])
 
+    def test_mets_basename(self):
+        with TemporaryDirectory() as tempdir:
+            with pushd_popd(tempdir):
+                result = self.runner.invoke(workspace_cli, ['-M', 'foo.xml', 'init', '.'])
+                self.assertEqual(result.exit_code, 0)
+                self.assertTrue(exists('foo.xml'))
+                self.assertFalse(exists('mets.xml'))
+
 if __name__ == '__main__':
     main()
Repository: ocr-d/core
Issue: workspace validator stopped working

There is a regression in 5ca8f7324b94cf0ea85d4afb9234d1f4296e7e96 (ocrd v2.1.1): 

```
Traceback (most recent call last):
  File "ocrd", line 8, in <module>
    sys.exit(cli())
  File "click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "click/decorators.py", line 64, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
TypeError: validate_workspace() got an unexpected keyword argument 'page_textequiv_consistency'
```

Click expects `page_textequiv_consistency` instead of the old `page_strictness` variant, because it is the __longer__ form:

> If all names for a parameter contain dashes, the internal name is generated automatically by taking the longest argument and converting all dashes to underscores.



Changed files:
ocrd/ocrd/cli/workspace.py

diff --git a/ocrd/ocrd/cli/workspace.py b/ocrd/ocrd/cli/workspace.py
index 514b8446..d23c2228 100644
--- a/ocrd/ocrd/cli/workspace.py
+++ b/ocrd/ocrd/cli/workspace.py
@@ -51,14 +51,14 @@ def workspace_cli(ctx, directory, mets_basename, backup):
 @click.option('--page-textequiv-consistency', '--page-strictness', help="How strict to check PAGE multi-level textequiv consistency", type=click.Choice(['strict', 'lax', 'fix', 'off']), default='strict')
 @click.option('--page-coordinate-consistency', help="How fierce to check PAGE multi-level coordinate consistency", type=click.Choice(['poly', 'baseline', 'both', 'off']), default='poly')
 @click.argument('mets_url')
-def validate_workspace(ctx, mets_url, download, skip, page_strictness, page_coordinate_consistency):
+def validate_workspace(ctx, mets_url, download, skip, page_textequiv_consistency, page_coordinate_consistency):
     report = WorkspaceValidator.validate(
         ctx.resolver,
         mets_url,
         src_dir=ctx.directory,
         skip=skip,
         download=download,
-        page_strictness=page_strictness,
+        page_strictness=page_textequiv_consistency,
         page_coordinate_consistency=page_coordinate_consistency
     )
     print(report.to_xml())
Repository: ocr-d/core
Issue: bagger bag regression from 1494e948

Our `ocrd zip bag` is currently broken: it now gives all files an additional `f.extension`, but then fails to also add that to the `f.url`, used in the METS [here](https://github.com/OCR-D/core/blob/1494e948ab9166b095e7855593df6048da4d1f68/ocrd/ocrd/workspace_bagger.py#L78), too.

Changed files:
ocrd/ocrd/workspace_bagger.py

diff --git a/ocrd/ocrd/workspace_bagger.py b/ocrd/ocrd/workspace_bagger.py
index 159d51bf..c1021cc4 100644
--- a/ocrd/ocrd/workspace_bagger.py
+++ b/ocrd/ocrd/workspace_bagger.py
@@ -78,7 +78,7 @@ class WorkspaceBagger():
                 if not isdir(file_grp_dir):
                     makedirs(file_grp_dir)
                 self.resolver.download_to_directory(file_grp_dir, f.url, basename="%s%s" % (f.ID, f.extension))
-                f.url = join(f.fileGrp, f.ID)
+                f.url = join(f.fileGrp, f.ID + f.extension)
 
             # save mets.xml
             with open(join(bagdir, 'data', ocrd_mets), 'wb') as f:
Repository: intake/intake-esm
Issue: to_dataset_dict not setting time.encoding when decode_times=True

It looks like `time.encoding` is not being set when I read in multiple files with `to_dataset_dict` with `decode_times=True`.

When you write a dataset to netCDF with no time encoding, the resulting time units end up differing from the original datasets, which I find to be unexpected behavior.

Following pydata/xarray#1614, a potential behavior is to keep the encoding from the first file. I think this is already being done for attributes.

Changed files:
tests/cmip6/test_cmip6.py, intake_esm/merge_util.py

diff --git a/intake_esm/merge_util.py b/intake_esm/merge_util.py
index a189ec3..b7e77e0 100644
--- a/intake_esm/merge_util.py
+++ b/intake_esm/merge_util.py
@@ -90,17 +90,35 @@ def aggregate(
 
             attrs = dict_union(*[ds.attrs for ds in dsets])
 
+            # copy encoding for each variable from first encounter
+            variables = set([v for ds in dsets for v in ds.variables])
+
+            encoding = {}
+            for ds in dsets:
+                for v in variables:
+                    if v in ds.variables and v not in encoding:
+                        if ds[v].encoding:
+                            encoding[v] = ds[v].encoding
+                            # get rid of the misleading file-specific attributes
+                            # github.com/pydata/xarray/issues/2550
+                            for enc_attrs in ['source', 'original_shape']:
+                                if enc_attrs in encoding[v]:
+                                    del encoding[v][enc_attrs]
+
             if agg_type == 'join_new':
                 ds = join_new(dsets, dim_name=agg_column, coord_value=keys, options=agg_options)
 
             elif agg_type == 'join_existing':
-
                 ds = join_existing(dsets, options=agg_options)
 
             elif agg_type == 'union':
                 ds = union(dsets, options=agg_options)
 
             ds.attrs = attrs
+            for v in ds.variables:
+                if v in encoding and not ds[v].encoding:
+                    ds[v].encoding = encoding[v]
+
             return ds
 
     return apply_aggregation(v)
diff --git a/tests/cmip6/test_cmip6.py b/tests/cmip6/test_cmip6.py
index 299bab1..bb0af21 100644
--- a/tests/cmip6/test_cmip6.py
+++ b/tests/cmip6/test_cmip6.py
@@ -38,6 +38,7 @@ def test_to_dataset_dict(esmcol_path, query, kwargs):
     _, ds = cat.to_dataset_dict().popitem()
     assert 'member_id' in ds.dims
     assert len(ds.__dask_keys__()) > 0
+    assert ds.time.encoding
 
 
 @pytest.mark.parametrize(