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

[MRG] add _init_kwargs to allow resetting raw object to the state after reading it in #5679

Merged
merged 4 commits into from
Nov 2, 2018

Conversation

jasmainak
Copy link
Member

@jasmainak jasmainak changed the title WIP check _init_kwargs WIP add _init_kwargs to allow resetting raw object to the state after reading it in Oct 30, 2018
@agramfort
Copy link
Member

agramfort commented Oct 30, 2018 via email

@jasmainak jasmainak force-pushed the reset_raw branch 6 times, most recently from 2de3292 to 67566ee Compare October 31, 2018 04:35
@jasmainak jasmainak changed the title WIP add _init_kwargs to allow resetting raw object to the state after reading it in [MRG] add _init_kwargs to allow resetting raw object to the state after reading it in Oct 31, 2018
@jasmainak
Copy link
Member Author

@agramfort good to go on my end. Tests pass locally on my box. Let's hope travis is also happy

@codecov
Copy link

codecov bot commented Oct 31, 2018

Codecov Report

Merging #5679 into master will increase coverage by <.01%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master    #5679      +/-   ##
==========================================
+ Coverage   88.48%   88.49%   +<.01%     
==========================================
  Files         369      369              
  Lines       69070    69074       +4     
  Branches    11651    11651              
==========================================
+ Hits        61116    61124       +8     
  Misses       5090     5090              
+ Partials     2864     2860       -4

# test resetting raw
raw2 = reader(**raw._init_kwargs)
assert set(raw.info.keys()) == set(raw2.info.keys())
assert_array_almost_equal(raw.times, raw2.times)
Copy link
Member

Choose a reason for hiding this comment

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

assert_array_equal should work here.

@agramfort
Copy link
Member

besides my nitpick LGTM

@jasmainak
Copy link
Member Author

comment addressed

@agramfort
Copy link
Member

@larsoner merge if you’re happy

@@ -179,6 +179,7 @@ def __init__(self, input_fname, ch_type, montage=None, eog=(), ecg=(),
info, preload, filenames=[input_fname], raw_extras=[header_info],
last_samps=last_samps, orig_format='int',
verbose=verbose)
self._init_kwargs = _get_argvalues()
Copy link
Member

Choose a reason for hiding this comment

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

Since all our readers must call the super init, a cleaner way to do this is call _get_argvalues in BaseRaw.__init__ and in _get_argvalues move up one stack frame before parsing

Copy link
Member

Choose a reason for hiding this comment

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

would it sill work from the super class given that not all params are passed to super?

Copy link
Member Author

@jasmainak jasmainak Nov 1, 2018

Choose a reason for hiding this comment

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

I think you could make it work by moving up one level in the stack before parsing but because BaseRaw is public, it could lead to unexpected/garbage in raw._init_kwargs if it was called by the user directly.

Copy link
Member

@larsoner larsoner Nov 1, 2018

Choose a reason for hiding this comment

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

I don't think we really need to worry about that corner case (at least on balance with the simplifications from the code we get by keeping it in moving it to BaseRaw).

Copy link
Member

Choose a reason for hiding this comment

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

... but if you are sufficiently worried about it, you could add a check that the function/method in the desired stacklevel is in the mne namespace. If it's not, set _init_kwargs = None or so.

@larsoner larsoner added this to the 0.17 milestone Nov 1, 2018
@jasmainak
Copy link
Member Author

@larsoner comments addressed.

@larsoner larsoner merged commit b71585b into mne-tools:master Nov 2, 2018
@larsoner
Copy link
Member

larsoner commented Nov 2, 2018

Thanks @jasmainak

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.

private attribute to detect if raw has been cropped?
3 participants