-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add reader for ANT Neuro format #12792
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
Conversation
|
One reasonable division would be to have This is similar to we would almost certainly implement something like |
|
That's the alternative.. A bit annoying now that I implemented both |
Not too late to yank that release :) And not too bad to copy the code over here, either. But more seriously you could in theory keep the code over there if you wanted. But I think it would make some maintenance stuff harder like if we deprecate something, move some private functions around, change stuff about how |
True, the biggest downside is that a breakage won't be immediately seen, except if some tests are also run in |
not sure what exactly you want to do with it, but does this help? import inspect
from types import FunctionType
from antio.io import read_raw_ant
params = inspect.signature(read_raw_ant).parameters
defaults = tuple(params[key].default for key in params)
func_in_mne_namespace = FunctionType(code=read_raw_ant.__code__, globals=globals(), argdefs=defaults)
func_in_mne_namespace.__doc__ = read_raw_ant.__doc__and now |
|
I don't think so, still learning something new in this snippet, but my issue was that I wanted to expose the signature and docstring from a function in an optional dependency, which might be absent from the environment. Anyway, I started moving the code/tests around in |
ah, yeah, I don't think that's possible. the |
i think we've had this discussion previously for bvio oder eeglabio, i don't remember ... but @sappelhoff and @cbrnr were involved |
|
This is now ready for review. Do we want to include it in
|
I would rather go with 1.9, gives us months to iron out bugs and actually try using it for a bit |
|
So we are going to include a binary extension now? I think this needs to be discussed with all devs. |
|
No the binary extension lives in the |
larsoner
left a comment
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.
Looks good, just a couple of comments!
mne/io/tests/test_read_raw.py
Outdated
| @pytest.fixture(scope="module") | ||
| def reader_excluded_from_read_raw() -> set[str]: | ||
| """Set of excluded readers from read_raw.""" | ||
| return { | ||
| "read_raw_bti", | ||
| "read_raw_hitachi", | ||
| "read_raw_neuralynx", | ||
| } | ||
|
|
||
|
|
||
| def test_all_reader_documented(reader_excluded_from_read_raw: set[str]): | ||
| """Test that all the readers in the documentation are accepted by read_raw.""" | ||
| readers = _get_supported() | ||
| # flatten the dictionaries and retrieve the function names | ||
| functions = [foo.__name__ for value in readers.values() for foo in value.values()] | ||
| # read documentation .rst source file | ||
| doc_file = Path(__file__).parents[3] / "doc" / "api" / "reading_raw_data.rst" | ||
| assert doc_file.exists() | ||
| with open(doc_file) as fid: | ||
| doc = fid.read() | ||
| reader_lines = [ | ||
| line.strip() for line in doc.split("\n") if line.strip().startswith("read_raw_") | ||
| ] | ||
| reader_lines = [ | ||
| elt for elt in reader_lines if elt not in reader_excluded_from_read_raw | ||
| ] | ||
| missing_from_read_raw = set(reader_lines) - set(functions) | ||
| missing_from_doc = set(functions) - set(reader_lines) | ||
| if len(missing_from_doc) != 0 or len(missing_from_read_raw) != 0: | ||
| raise AssertionError( | ||
| "Functions missing from documentation:\n\t" | ||
| f"{'\n\t'.join(missing_from_doc)}\n\n" | ||
| "Functions missing from read_raw:\n\t" | ||
| f"{'\n\t'.join(missing_from_read_raw)}" | ||
| ) | ||
| if sorted(reader_lines) != list(reader_lines): | ||
| raise AssertionError( | ||
| "Functions in documentation are not sorted. Expected order:\n\t" | ||
| f"{'\n\t'.join(sorted(reader_lines))}" | ||
| ) | ||
|
|
||
|
|
||
| def test_all_reader_documented_in_docstring(): | ||
| """Test that all the readers are documented in read_raw docstring.""" | ||
| readers = _get_supported() | ||
| # flatten the dictionaries and retrieve the function names | ||
| functions = [foo.__name__ for value in readers.values() for foo in value.values()] | ||
| doc = read_raw.__doc__.split("Parameters")[0] | ||
| documented = [elt.strip().split("`")[0] for elt in doc.split("mne.io.")[1:]] | ||
| missing_from_docstring = set(functions) - set(documented) | ||
| if len(missing_from_docstring) != 0: | ||
| raise AssertionError( | ||
| "Functions missing from docstring:\n\t" | ||
| f"{'\n\t'.join(missing_from_docstring)}" | ||
| ) | ||
| if sorted(documented) != documented: | ||
| raise AssertionError("Functions in docstring are not sorted.") |
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.
@larsoner I added those 2 tests, it did catch a couple of missing readers, 3 of which I excluded because they require a folder or an extension-less file as input.
|
Finally green 🎉 |
larsoner
left a comment
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.
Just some small optional ideas, feel free to change them or not then we can merge!
| ) | ||
| if sorted(reader_lines) != list(reader_lines): | ||
| raise AssertionError( | ||
| "Functions in documentation are not sorted. Expected order:\n\t" |
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.
Nice!
Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
Closes #3609
Getting the ball rolling now that a first version of
antiois up on PyPI. Open items:I'm not finding a nice way to pull the functionantio.io.read_raw_antand its docstring fromantio, which forces the signature and docstring copy/paste..How to tests without duplicating the tests inantioMaybe it wasn't that smart to defineRawANTandread_raw_antinantio.. the rationale was to move all maintenance of the reader toantio.