question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use properties to set values in Info

See original GitHub issue

As I’ve mentioned in #7816 I think it would be more intuitive if users could just set values in the Info dict using simple assignments, e.g. info['meas_date'] = None, instead of setter methods (e.g. info.set_meas_date(None)). This is consistent with values that we currently allow to be set directly, e.g. info["bads"] = [].

This would also allow us to make read-only properties for fields which users should not set manually.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:13 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
cbrnrcommented, May 25, 2020

No, this is just about the Info object. Intended changed usage examples:

>>> raw.info["bads"] = ["C3", "Cz", "C4"]
>>> raw.info["annotations"] = mne.Annotations(mne.Annotations(5, 1, "test"))
>>> raw.info["sfreq"] = 254
AttributeError: sampling frequency cannot be changed (consider resampling the signal)
>>> raw.info["ch_names"] = ["X", "Y"]
ValueError: number of channel names (2 given) must match number of channels (32)
>>> raw.info["nchan"] = 30
AttributeError: number of channels cannot be set (consider using drop_channels)
1reaction
cbrnrcommented, May 24, 2020

I totally agree with you - that’s why I’d use properties instead of setters.

Read more comments on GitHub >

github_iconTop Results From Across the Web

PropertyInfo.SetValue Method (System.Reflection)
When overridden in a derived class, sets the property value for a specified object that has the specified binding, index, and culture-specific information....
Read more >
c# - Setting a property by reflection with a string value
Ship ship = new Ship(); string value = "5.5"; var property = ship.GetType().GetProperty("Latitude"); var convertedValue = property.Converter.
Read more >
How to Set Property Value using Reflection on a Value Type
PropertyInfo.SetValue method receives a System.Object as its first argument, and that is the instance on which property value should be set.
Read more >
How to set a property value by reflection in C#? - Tutorialspoint
Reflection objects are used for obtaining type information at runtime. ... Sets the property value of a specified object.
Read more >
PropertyInfo.SetValue - John Nelson's Blog
To set property values via Reflection, you must use the Type.GetProperty() method, then invoke the PropertyInfo.SetValue() method. The default overload that ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found