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

Fix patching a table with a DataFrame with a custom index #5645

Merged
merged 2 commits into from
Oct 16, 2023

Conversation

maximlt
Copy link
Member

@maximlt maximlt commented Oct 16, 2023

Fixes #5554

@codecov
Copy link

codecov bot commented Oct 16, 2023

Codecov Report

Merging #5645 (159c0d1) into main (db1e9fe) will decrease coverage by 0.05%.
Report is 2 commits behind head on main.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #5645      +/-   ##
==========================================
- Coverage   83.65%   83.60%   -0.05%     
==========================================
  Files         280      280              
  Lines       41580    41635      +55     
==========================================
+ Hits        34782    34811      +29     
- Misses       6798     6824      +26     
Flag Coverage Δ
ui-tests 39.55% <29.50%> (-0.03%) ⬇️
unitexamples-tests 73.68% <100.00%> (-0.06%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
panel/tests/widgets/test_tables.py 99.79% <100.00%> (+0.01%) ⬆️
panel/widgets/tables.py 88.86% <100.00%> (+0.08%) ⬆️

... and 7 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@maximlt
Copy link
Member Author

maximlt commented Oct 16, 2023

The examples tests are failing on the reference/widgets/DataFrame.ipynb notebook. .patch is exerted in this notebook in the following way:

import pandas as pd
import panel as pn

pn.extension()

df = pd.DataFrame({'int': [1, 2, 3], 'float': [3.14, 6.28, 9.42], 'str': ['A', 'B', 'C'], 'bool': [True, False, True]}, index=[1, 2, 3])
table = pn.widgets.DataFrame(df)
table.patch({
    'bool': [
        (0, False),
        (2, False)
    ],
    'int': [
        (slice(0, 2), [3, 2])
    ]
})

Note that the index of the DataFrame is [1, 2, 3] so not the default DataFrame index.

The default of .patch() is as_index=True which means that the indexes should be treated as DataFrame indexes, not as simple integer indexes. I think the example in the notebook is leveraging a bug so I'll update it.

Copy link
Member

@philippjfr philippjfr left a comment

Choose a reason for hiding this comment

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

This looks great, thank you for adding the tests!

@philippjfr philippjfr merged commit 9a70094 into main Oct 16, 2023
11 of 15 checks passed
@philippjfr philippjfr deleted the fix_patch_non_monotonic branch October 16, 2023 13:52
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.

Patching fails with DataFrame that don't have a monotonic range
2 participants