-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
PR: Remember format for floats in DataFrame editor #3611
Conversation
LGTM :-) I would say marge, but we are waiting on @ccordoba12 3.02 release :-) |
for name in REMOTE_SETTINGS: | ||
settings[name] = CONF.get(VariableExplorer.CONF_SECTION, name) | ||
settings[name] = CONF.get(section, name) |
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.
I don't know why this was written like this before, but now you should be able to use self.get_option
here (instead of calling CONF
directly)
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.
This is a static method so there is no self
. I will convert it to a normal method but I discovered that it is called in a number of places so I need to change them ...
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.
Ok, thanks for looking at this. I think it'd be nicer to have it as a method.
At the moment, this signal can only come from a DataFrameEditor. | ||
""" | ||
assert option_name == 'dataframe_format' | ||
self.parent().set_dataframe_format(new_value) |
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.
Could we move this method to dataframeeditor
? It has nothing to do with collectionseditor
:-)
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.
The collectionseditor
creates the dataframeeditor
so it has to inject the relevant configuration options (here only the dataframe format) in the dataframeeditor
.
As I understand the widget/plugin separation, widgets should get all relevant configuration options at creation time. Widgets are not supposed to query the corresponding plugin because it should be possible to run them stand alone. In this instance, the collectioneditor
needs to keep track of the dataframe format, so I don't see how to move this method to dataframeeditor
.
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.
You're right. I tried to come up with a better design but yours is the only viable alternative I can see.
Let's modify this couple of lines to
if option_name == 'dataframe_format':
self.parent().set_dataframe_format(new_value)
to not make change_option
too restrictive.
This looks very good to me. I just added some comments to simplify the code a little bit ;-) |
@malliwi88 this also needs a rebase/merge with 3.x now :-) |
The format is stored without a percent sign in the user configuration (e.g., '.3g' instead of '%.3g'), because otherwise the percent sign would interfere with ConfigParser's interpolation feature.
- Change get_settings() in variable explorer plugin to also retreive the dataframe_format setting. - The setting is then passed to the NamespaceBrowser widget by add_shellwidget(). - Add a member variable to NamespaceBrowser for storing the setting. - Extend NamespaceBrowser.setup() to set the setting.
- Add ReadOnlyCollectionsModel member variable to store the config setting, and set it in its initializer. - Change initializer of RemoteCollectionsEditorTableView to accept the config setting and pass it on when constructing a ReadOnlyCollectionsModel. - Change NamespaceBrowser.setup() to pass on the setting when constructing a RemoteCollectionsEditorTableView. - Add a test.
- In CollectionsDelegate.createEditor(), when creating a DataFrameEditor, call set_format with the config setting. - Add a test.
- Add a signal sig_option_changed to DataFrameEditor. - Raise this signal in change_format(). - Add a test.
- When creating a DataFrameEditor in CollectionsDelegate.createEditor(), connect its sig_option_changed signal to the new .change_option() function. - Add CollectionsDelegate.change_option(), to call BaseTableView.set_dataframe_format() on the table view of the collection editor. - Add a test.
- In VariableExplorer.add_shellwidget(), connect sig_option_changed from the newly created NamespaceBrowser to a new .change_option() member function. - Add VariableExplorer.change_option() to check whether the option being changed is the dataframe format, in which case the leading '%' character from the format is stripped. Then sig_option_changed is emitted from the plugin, which leads to the new config setting being saved.
Commit da2aa25 broke the assert.
This hopefully resolves flaky tests on qt4 caused by lingering DataFrameModel.
Add full stops to some comments; remove one out-dated comment; use .format() for formatting.
If user changes the format in the dataframe editor and provides a format which does not start with '%', then (without this commit) the assert in VariableExplorer.change_option() will be triggered.
d765a74
to
7df80b9
Compare
Rebased but I still have to look at the comments re |
7df80b9
to
8d0dc3a
Compare
As a consequence. VariableExplorer.get_settings() converts from a static method to a normal method.
I replied to the comment re |
""" | ||
section = VariableExplorer.CONF_SECTION |
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.
This variable is not needed anymore.
I suggested a last couple of changes, then I'd say it's ready to merge :-) |
Also remove an unused variable.
Done |
Ok, thanks a lot @jitseniesen! |
Fixes #2728 Conflicts: - spyder/widgets/variableexplorer/collectionseditor.py - spyder/widgets/variableexplorer/namespacebrowser.py
Fixes #2728.
This is #3539
raised from the deadbut based now against 3.x branch.This pull request is to make Spyder remember the format that the user sets for floats in the DataFrameEditor by storing it in the user configuration settings.
dataframe_format
is introduced in the variable explorer section in the user config. This setting contains the format, without the leading%
character (e.g., if the format is'%.3f'
then the setting is stored as'.3f'
). The reason for this is that it is apparently impossible to have a config setting with a%
character, because this is used inConfigParser
for interpolation.%
character in the front) from theVariableExplorer
plugin via theNamespaceBrowser
andCollectionEditor
widgets to theDataFrameEditor
widget, where it is used to set the format for floats.DataFrameEditor
widget, then this information is passed back using asig_option_changed
signal viaCollectionEditor
andNamespaceBrowser
toVariableExplorer
. There the leading%
character is stripped and the format is stored in the user config.