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

Only perform header detection when --file is specified #80

Merged
merged 3 commits into from
Jan 18, 2023

Conversation

sbesson
Copy link
Member

@sbesson sbesson commented Jan 5, 2023

This PR attempts to fix a regression introduced as part of #67 which was primarily tested with the omero metadata populate command

To reproduce, run a workflow composed of a table population followed by a bulk annotation -> map annotation population, for instance as described with https://omero-guides.readthedocs.io/en/latest/upload/docs/metadata.html.

With the current release of omero-metadata 0.11.1, the second step should fail with and error of type

$ omero metadata populate --context bulkmap --cfg simple-annotation-bulkmap-config.yml Dataset:601
Using session for import.user@localhost:4064. Idle timeout: 10 min. Current group: Demo Group
Traceback (most recent call last):
  File "/opt/omero/OMERO.venv/bin/omero", line 8, in <module>
    sys.exit(main())
  File "/opt/omero/OMERO.venv/lib/python3.8/site-packages/omero/main.py", line 126, in main
    rv = omero.cli.argv()
  File "/opt/omero/OMERO.venv/lib/python3.8/site-packages/omero/cli.py", line 1787, in argv
    cli.invoke(args[1:])
  File "/opt/omero/OMERO.venv/lib/python3.8/site-packages/omero/cli.py", line 1225, in invoke
    stop = self.onecmd(line, previous_args)
  File "/opt/omero/OMERO.venv/lib/python3.8/site-packages/omero/cli.py", line 1302, in onecmd
    self.execute(line, previous_args)
  File "/opt/omero/OMERO.venv/lib/python3.8/site-packages/omero/cli.py", line 1384, in execute
    args.func(args)
  File "/opt/omero/OMERO.venv/lib/python3.8/site-packages/omero_metadata/cli.py", line 578, in populate
    first_row = pd.read_csv(args.file, nrows=1, header=None)
  File "/opt/omero/OMERO.venv/lib/python3.8/site-packages/pandas/util/_decorators.py", line 211, in wrapper
    return func(*args, **kwargs)
  File "/opt/omero/OMERO.venv/lib/python3.8/site-packages/pandas/util/_decorators.py", line 331, in wrapper
    return func(*args, **kwargs)
  File "/opt/omero/OMERO.venv/lib/python3.8/site-packages/pandas/io/parsers/readers.py", line 950, in read_csv
    return _read(filepath_or_buffer, kwds)
  File "/opt/omero/OMERO.venv/lib/python3.8/site-packages/pandas/io/parsers/readers.py", line 605, in _read
    parser = TextFileReader(filepath_or_buffer, **kwds)
  File "/opt/omero/OMERO.venv/lib/python3.8/site-packages/pandas/io/parsers/readers.py", line 1442, in __init__
    self._engine = self._make_engine(f, self.engine)
  File "/opt/omero/OMERO.venv/lib/python3.8/site-packages/pandas/io/parsers/readers.py", line 1735, in _make_engine
    self.handles = get_handle(
  File "/opt/omero/OMERO.venv/lib/python3.8/site-packages/pandas/io/common.py", line 713, in get_handle
    ioargs = _get_filepath_or_buffer(
  File "/opt/omero/OMERO.venv/lib/python3.8/site-packages/pandas/io/common.py", line 451, in _get_filepath_or_buffer
    raise ValueError(msg)
ValueError: Invalid file path or buffer object type: <class 'NoneType'>

With this PR included, both population steps should successfully complete.

Given the regression, I would propose to schedule this in an upcoming patch release 0.11.2 (possibly together with #79)

For other populate contexts (bulkmap, deletemap), this parsing is
irrelevant and should be skipped
@sbesson sbesson requested review from pwalczysko and muhanadz January 5, 2023 11:32
Copy link
Member

@muhanadz muhanadz left a comment

Choose a reason for hiding this comment

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

Thank you for opening the PR Seb. Changes are necessary and probably overlooked/missed in the previous PR. Tested and, as detailed in the description, this PR fixes ValueError: Invalid file path or buffer object type: <class 'NoneType'> exception as a result of running the bulk annotation workflow.

I agree with the including this in a 0.11.2 patch release.

@sbesson sbesson closed this Jan 5, 2023
@sbesson sbesson reopened this Jan 5, 2023
@pwalczysko
Copy link
Member

pwalczysko commented Jan 5, 2023

Confirming the error with 0.11.2, see below

omero metadata populate --context bulkmap --cfg ~/Downloads/simple-annotation-bulkmap-config.yml --batch 100 Dataset:117 
Using session for user-1@localhost:4064. Idle timeout: 10 min. Current group: group1
Traceback (most recent call last):
  File "/Users/pwalczysko/opt/anaconda3/envs/cli/bin/omero", line 10, in <module>
    sys.exit(main())
  File "/Users/pwalczysko/opt/anaconda3/envs/cli/lib/python3.8/site-packages/omero/main.py", line 126, in main
    rv = omero.cli.argv()
  File "/Users/pwalczysko/opt/anaconda3/envs/cli/lib/python3.8/site-packages/omero/cli.py", line 1787, in argv
    cli.invoke(args[1:])
  File "/Users/pwalczysko/opt/anaconda3/envs/cli/lib/python3.8/site-packages/omero/cli.py", line 1225, in invoke
    stop = self.onecmd(line, previous_args)
  File "/Users/pwalczysko/opt/anaconda3/envs/cli/lib/python3.8/site-packages/omero/cli.py", line 1302, in onecmd
    self.execute(line, previous_args)
  File "/Users/pwalczysko/opt/anaconda3/envs/cli/lib/python3.8/site-packages/omero/cli.py", line 1384, in execute
    args.func(args)
  File "/Users/pwalczysko/opt/anaconda3/envs/cli/lib/python3.8/site-packages/omero_metadata/cli.py", line 578, in populate
    first_row = pd.read_csv(args.file, nrows=1, header=None)
  File "/Users/pwalczysko/opt/anaconda3/envs/cli/lib/python3.8/site-packages/pandas/util/_decorators.py", line 211, in wrapper
    return func(*args, **kwargs)
  File "/Users/pwalczysko/opt/anaconda3/envs/cli/lib/python3.8/site-packages/pandas/util/_decorators.py", line 331, in wrapper
    return func(*args, **kwargs)
  File "/Users/pwalczysko/opt/anaconda3/envs/cli/lib/python3.8/site-packages/pandas/io/parsers/readers.py", line 950, in read_csv
    return _read(filepath_or_buffer, kwds)
  File "/Users/pwalczysko/opt/anaconda3/envs/cli/lib/python3.8/site-packages/pandas/io/parsers/readers.py", line 605, in _read
    parser = TextFileReader(filepath_or_buffer, **kwds)
  File "/Users/pwalczysko/opt/anaconda3/envs/cli/lib/python3.8/site-packages/pandas/io/parsers/readers.py", line 1442, in __init__
    self._engine = self._make_engine(f, self.engine)
  File "/Users/pwalczysko/opt/anaconda3/envs/cli/lib/python3.8/site-packages/pandas/io/parsers/readers.py", line 1735, in _make_engine
    self.handles = get_handle(
  File "/Users/pwalczysko/opt/anaconda3/envs/cli/lib/python3.8/site-packages/pandas/io/common.py", line 713, in get_handle
    ioargs = _get_filepath_or_buffer(
  File "/Users/pwalczysko/opt/anaconda3/envs/cli/lib/python3.8/site-packages/pandas/io/common.py", line 451, in _get_filepath_or_buffer
    raise ValueError(msg)
ValueError: Invalid file path or buffer object type: <class 'NoneType'>

@pwalczysko
Copy link
Member

With this PR, I get

omero metadata populate --context bulkmap --cfg ~/Downloads/simple-annotation-bulkmap-config.yml --batch 100 Dataset:117
Using session for user-1@localhost:4064. Idle timeout: 10 min. Current group: group1
INFO:omero_metadata.populate:Created/linked 100 MapAnnotations (total 100)
INFO:omero_metadata.populate:Created/linked 65 MapAnnotations (total 165)

and indeed, the MapAnnotations are created as expected:

Screenshot 2023-01-05 at 15 12 35

LGTM

@sbesson
Copy link
Member Author

sbesson commented Jan 5, 2023

Pushed another commit with the changelog entry if we are happy with an immediate 0.11.2 @jburel @joshmoore

@sbesson sbesson requested review from jburel and joshmoore January 5, 2023 15:38
Copy link
Member

@jburel jburel left a comment

Choose a reason for hiding this comment

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

sorry for dropping that one.
Looks good

@sbesson
Copy link
Member Author

sbesson commented Jan 17, 2023

@jburel do you have any timeline for making a release of this plugin (and/or would you like me to do it)? I think it would be valuable to upgrade the version of the plugin deployed on prod114 so that we can test the whole annotation workflow with the new pandas functionality on the next studies. /cc @dominikl

@jburel
Copy link
Member

jburel commented Jan 17, 2023

@sbesson your suggestion to deploy the plugin on prod114 makes sense.
If you can take care of the release, that will be great

@sbesson sbesson merged commit 3c5dce5 into ome:master Jan 18, 2023
@sbesson sbesson deleted the headerdetection_bulkmap_fix branch January 18, 2023 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants