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

Exception on programmable deleting of selected rows() #208

Open
GBR-613 opened this issue Jan 9, 2022 · 4 comments
Open

Exception on programmable deleting of selected rows() #208

GBR-613 opened this issue Jan 9, 2022 · 4 comments

Comments

@GBR-613
Copy link

GBR-613 commented Jan 9, 2022

The following exception is thrown:

  File "c:\Programs\Python37\lib\site-packages\pandastable\core.py", line 488, in redraw
    self.redrawVisible(event, callback)
  File "c:\Programs\Python37\lib\site-packages\pandastable\core.py", line 470, in redrawVisible
    self.colorRows()
  File "c:\Programs\Python37\lib\site-packages\pandastable\core.py", line 581, in colorRows
    colors = rc[colname].loc[idx]
  File "c:\Programs\Python37\lib\site-packages\pandas\core\indexing.py", line 879, in __getitem__
    return self._getitem_axis(maybe_callable, axis=axis)
  File "c:\Programs\Python37\lib\site-packages\pandas\core\indexing.py", line 1099, in _getitem_axis
    return self._getitem_iterable(key, axis=axis)
  File "c:\Programs\Python37\lib\site-packages\pandas\core\indexing.py", line 1037, in _getitem_iterable
    keyarr, indexer = self._get_listlike_indexer(key, axis, raise_missing=False)
  File "c:\Programs\Python37\lib\site-packages\pandas\core\indexing.py", line 1254, in _get_listlike_indexer
    self._validate_read_indexer(keyarr, indexer, axis, raise_missing=raise_missing)

Please notice: although it occurs frequently, I don't have steadily reproduced scenario.
During the debugging, I noticed that index of self.rowcolors does not match the actual self.model.df.

@GBR-613
Copy link
Author

GBR-613 commented Jan 9, 2022

The same problem after adding new row using table.model.addRow(), then table.model.setValueAt()
(BTW why they are not combined?)
Probably fixing after adding an extra call to table.resetColors().
I tend to assume that it should be called into table.redrawVisible().

@dmnfarrell
Copy link
Owner

The problem is the color dataframe is not synced when rows are added/deleted. I think the method of implementing using a parallel dataframe colors is too fragile. table.update_rowcolors() is meant to check they are synced.
It's now called in addRow which is renamed to insertRow. Not sure it fixes this.

@GBR-613
Copy link
Author

GBR-613 commented Jan 30, 2022

@dmnfarrell 1. Don't you think that update_rowcolors() should always be called into insertRow() and deleteRows()?
2. Don't you think that resetIndex() should also always be called there? I believe the "visible" index (the one shown in a gray column just left to the table) should always reflect the real index.

@dmnfarrell
Copy link
Owner

  1. I did add it to insertRow. It's also called in table.deleteRow.
  2. calling reset_index might solve one problem but create more. It could mess up the users index. the index is used for plotting e.g. you might have dates in the index. That's why I have the option to show just row numbers like a spreadsheet or the index. Possibly it is confusing. Maybe I should prevent cell coloring at all for non integer indexes, otherwise it could start to fail. That's what I meant by fragile. I would advise if you are using row coloring only use simple indexes and you can always reset the index yourself. The code needs cleaning up but I have not had the time.

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

No branches or pull requests

2 participants