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.

Sync modifications in GUI to iPython & record history

See original GitHub issue

I noticed that you’re looking for feedback… and I think this project is on to something…

My dream DataFrame viewer would work like this:

from pandasgui import DataFrameViewer
viewer = DataFrameViewer()
viewer.open()  # opens a GUI window
viewer.bind(df1)  # tab 1 in the viewer
viewer.bind(df2)  # tab 2 in the viewer
viewer.bind(df3)  # tab 3 in the viewer

Now when you change a cell value in the GUI, the application “pushes” the code to the python/ipython shell i.e., you see df1.at['row', 'col'] = 10 in the shell.

Moreover, if you type df1.at['row', 'col'] = 20 in the shell, the value automatically changes in the GUI. I think such an application would be 1000+ Github stars in no time.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
adamerosecommented, Oct 26, 2020

A quick note about the recorded history of operations on a data frame in the GUI. How are you applying the filter queries to a dataframe. Through parsing them into pandas operations? You could use the same mechanism to reapply the filters given the filter queries in your top left section. This will make operations performed in the gui reproducible using pandas gui own filtering routine. You can save the operation history string (list of strings) as an attribute in the gui class and should be straight forward to update every time a filter is added or cell is edited.

Then reapply the filters will become something like

from pandasgui import apply_filters
...
h = gui.history
h
['60<hp<70','Name == Abra']

df_processed = apply_filters(h, df)

The part that actually applies the filters is just a loop with df = df.query(filt.expr), that method does the parsing and applying the operations. It happens in store.py like this:

    @track_history
    def add_filter(self, expr: str, enabled=True):
        filt = Filter(expr=expr, enabled=enabled, failed=False)
        self.filters.append(filt)
        self.apply_filters()

    @track_history
    def remove_filter(self, index: int):
        self.filters.pop(index)
        self.apply_filters()

    @track_history
    def edit_filter(self, index: int, expr: str):
        filt = self.filters[index]
        filt.expr = expr
        filt.failed = False
        self.apply_filters()

    @track_history
    def toggle_filter(self, index: int):
        self.filters[index].enabled = not self.filters[index].enabled
        self.apply_filters()

    def apply_filters(self):

        df = self.dataframe_original
        for ix, filt in enumerate(self.filters):
            if filt.enabled and not filt.failed:
                try:
                    df = df.query(filt.expr)
                except Exception as e:
                    self.filters[ix].failed = True
                    logger.exception(e)
        self.dataframe = df
        self.update()

And those @track_history decorated methods will show up in the history like this

HistoryItem(name='add_filter', args=(), kwargs={'expr': 'HP > 56'}, time='10:46:09')
HistoryItem(name='add_filter', args=(), kwargs={'expr': '`Type 1` == "Grass"'}, time='10:46:18')
HistoryItem(name='toggle_filter', args=(1,), kwargs={}, time='10:46:21')
HistoryItem(name='toggle_filter', args=(1,), kwargs={}, time='10:46:22')
HistoryItem(name='remove_filter', args=(1,), kwargs={}, time='10:47:10')

So I’m already storing a history of these methods and arguments, it’s just going beyond this and being able to generate runnable code is where things get tricky, since these methods often reference self or the data store which wouldn’t exist in a user’s script

0reactions
KobaKhitcommented, Oct 26, 2020

Does not have to bu runnable code. Can be a just a function or method as long as it allows to convenietnly reproduce the processed data frame. If you are open to commits I could look into creating a convenient way to reapply to filters from history.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sync modifications in GUI to iPython & record history · Issue #20
It would be. The idea is that you can edit cells/columns/rows in the GUI and those commands would be "recorded" in iPython. ......
Read more >
How to log IPython history to text file? - Stack Overflow
You can export all of your history in IPython to a text file with the %history magic like this: %history -g -f filename....
Read more >
Built-in magic commands — IPython 8.7.0 documentation
By default, the 'processed' history is used, so that magics are loaded in their transformed version to valid Python. If this option is...
Read more >
Introduction to IPython configuration - documentation
The IPython directory​​ IPython stores its files—config, command history and extensions—in the directory ~/. ipython/ by default. If set, this environment ...
Read more >
Jupyter Notebook files - GitLab Docs
Jupyter Notebook (previously, IPython Notebook) files are used for interactive computing in many fields. They contain a complete record of the user's ...
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