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

Allow search of ids in ElementIdentifiers #187

Merged
merged 5 commits into from
Nov 3, 2019
Merged

Allow search of ids in ElementIdentifiers #187

merged 5 commits into from
Nov 3, 2019

Conversation

oruebel
Copy link
Contributor

@oruebel oruebel commented Oct 25, 2019

Motivation

This is to allow us to address oruebel/ndx-icephys-meta#9 When creating references to DynamicTable we often don't know the indices of the rows we need but only the list of ids. With this we can now do:

dst = DynamicTable(.....)
rows_with_ids = dst[ dst.id == [0,10] ]

Checklist

  • Have you checked our Contributing document?
  • Have you ensured the PR description clearly describes problem and the solution?
  • Is your contribution compliant with our coding style ? This can be checked running flake8 from the source directory.
  • Have you checked to ensure that there aren't other open Pull Requests for the same change?
  • Have you included the relevant issue number using #XXX notation where XXX is the issue number ? By including "Fix #XXX" you allow GitHub to close the corresponding issue.

@codecov
Copy link

codecov bot commented Oct 25, 2019

Codecov Report

Merging #187 into dev will increase coverage by 0.04%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##              dev     #187      +/-   ##
==========================================
+ Coverage   70.32%   70.36%   +0.04%     
==========================================
  Files          30       30              
  Lines        5911     5916       +5     
  Branches     1381     1382       +1     
==========================================
+ Hits         4157     4163       +6     
+ Misses       1323     1322       -1     
  Partials      431      431
Impacted Files Coverage Δ
src/hdmf/common/table.py 54.98% <100%> (+0.88%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b247ad6...1fbe9fd. Read the comment docs.

'of the found elements, rather than in the order in which the elements'
'where given for the search. Also the length of the result may be different from the length'
'of the input array. E.g., if our ids are [1,2,3] and we are search for [3,1,5] the '
'result would be [0,2] and NOT [2,0,None]')
Copy link
Contributor

@rly rly Oct 25, 2019

Choose a reason for hiding this comment

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

I think for docval to do its intended behavior, the function has to be defined as def __eq__(self, **kwargs). Given that this function must be def __eq__(self, other) in order to override the == functionality, the docval decorator should be replaced with a docstring. Then it is clear that validation and all the other docval functionality does not run.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rly @ajtritt I added in fe6f124 a test to check if docval correctly performs the type checking and it seems to work fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I.e., the test in ed95b58 actually tests this and seems fine too

Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting. So it does work then. Out of curiousity, does the name need to match the name of the variable? Or is it just doing positional arg matching?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When calling ElementIdentifiers == 1 Python will pass as a positional argument, i.e., the error checking in docval happens for this here

hdmf/src/hdmf/utils.py

Lines 423 to 436 in 8ddae22

parsed = __parse_args(
_copy.deepcopy(loc_val),
args[1:],
kwargs,
enforce_type=enforce_type,
enforce_shape=enforce_shape,
allow_extra=allow_extra)
for error_type, ExceptionType in (('type_errors', TypeError),
('value_errors', ValueError)):
parse_err = parsed.get(error_type)
if parse_err:
msg = ', '.join(parse_err)
raise_from(ExceptionType(msg), None)
The name of the docval argument and the argument of the __eq__ function need to match, e.g, if I change the docval argname it something you would get TypeError: __eq__() got an unexpected keyword argument 'something'

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.

2 participants