Add is_header_parsed
flag to quickly check if header information is available in BaseRawIO
#1388
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
BaseRawIO
class has the methodparse_header
that extracts all the information from the formats and therefore is usually a computational heavy process:https://github.com/h-mayorquin/python-neo/blob/e3742da276fe3bb9a1ea327489ebdbf06c026956/neo/rawio/baserawio.py#L166-L181
I propose adding a simple flag called
is_header_parsed
that is set toTrue
after the header is parsed (i.e.parse_header
is called). That way, users can check quickly if the header is alredy parsed without having to check for the contents of the header directly.That is, we follow the mantra that "explicit is better than implicit" here from the Zen.
Use case in point:
From spikeinterface, we sometimes require one or two properties from the header before intializing the neo reader:
https://github.com/h-mayorquin/spikeinterface/blob/1b8ae2c0907aee49ca9cb44e19c78d9bbfadf6e2/src/spikeinterface/extractors/neoextractors/plexon.py#L62-L64
However, within the neo base extractor we then re-parse the whole file at initialization:
https://github.com/h-mayorquin/spikeinterface/blob/1b8ae2c0907aee49ca9cb44e19c78d9bbfadf6e2/src/spikeinterface/extractors/neoextractors/neobaseextractor.py#L40-L64
We could avoid this with an explicit flag such as the one proposed into the PR without having to make assumptions about what is on the header attribute.
@alejoe91 @weiglszonja