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 ValueError check in ColumnDataSource.patch #14020

Merged
merged 3 commits into from
Aug 14, 2024

Conversation

cdeil
Copy link
Contributor

@cdeil cdeil commented Aug 11, 2024

Fix an error where ColumnDataSource.patch was doing some ValueError reporting but trying to format a list ind as a int %d which when executed would raise TypeError. I'm not familiar with the code (was just pointed out by PyCharm) but I suppose using the int ind_0 was intended?

Copy link

codecov bot commented Aug 11, 2024

Codecov Report

Attention: Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.

Please upload report for BASE (branch-3.6@5aecc61). Learn more about missing BASE report.

Additional details and impacted files
@@              Coverage Diff              @@
##             branch-3.6   #14020   +/-   ##
=============================================
  Coverage              ?   93.20%           
=============================================
  Files                 ?      282           
  Lines                 ?    19850           
  Branches              ?        0           
=============================================
  Hits                  ?    18501           
  Misses                ?     1349           
  Partials              ?        0           

@mattpap mattpap added this to the 3.6 milestone Aug 11, 2024
@mattpap
Copy link
Contributor

mattpap commented Aug 11, 2024

While you are at it, I would suggest adding some simple with pytest.raises(...) style of tests to cover those cases.

@cdeil
Copy link
Contributor Author

cdeil commented Aug 11, 2024

I have not managed to get a proper dev setup working yet on MacOS, still struggling with various issues. So would appreciate if you could add more tests if needed for now.

@bryevdv
Copy link
Member

bryevdv commented Aug 11, 2024

There's no pressing hurry, it seems like this would be a good context to get tests up and running locally.

@bryevdv bryevdv added the python Issues that should only require updating Python code label Aug 11, 2024
@cdeil
Copy link
Contributor Author

cdeil commented Aug 11, 2024

This now works for me:

pytest --cov=bokeh --cov-report=html -m "not selenium" tests/unit

Is it the proper way or are there other relevant tests?

It looks like there's missing unit test coverage here for some types of patches and not just the exception handler lines I fixed:

Screenshot 2024-08-11 at 23 31 00 Screenshot 2024-08-11 at 23 33 02

@cdeil
Copy link
Contributor Author

cdeil commented Aug 11, 2024

I'm really not familiar with this code at all and don't know what "correct" would look like here, what inputs exactly should or shouldn't work. Would be great if someone familiar with the code can add the missing test(s) and finish this up!

@bryevdv
Copy link
Member

bryevdv commented Aug 12, 2024

@cdeil I would expect the tests for error conditions would all look very similar to this (untested):

def test_bad_negative_index() -> None:
    source = ColumnDataSource(data=dict(foo=[1]))
    bad_patch = dict(foo=(-1, 10))

    msg = "Out-of bounds index (-1) in patch for column: foo"
    with pytest.raises(ValueError, match=msg):
        source.patch(bad_patch)

The hierarchy for test files under tests/unit exactly matches the library file hierarchy with test_ prefixed, so this would go in the corresponding test_sources.py module.

I'm not sure when I would be able to add tests so we can just leave this open for the time being.

@cdeil
Copy link
Contributor Author

cdeil commented Aug 14, 2024

Added some tests: b7cdbe0

with pytest.raises(ValueError, match=r"Can only sub-patch into columns with NumPy array items"):
ds.patch(dict(foo=[[[0, 3], 5]]))
with pytest.raises(ValueError, match=r"Invalid patch index: {}"):
ds.patch(dict(foo=[[{}, 5]]))
Copy link
Member

@bryevdv bryevdv Aug 14, 2024

Choose a reason for hiding this comment

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

Thanks for the tests! I won't hold up this PR but I will mention just for FYI that typically we would split these into multiple named tests in order to have finer grained test resolution. Gold standard for individual tests is AAA — "Arrange, Act, Assert" ideally with one assertion or only a few closely related assertions for a single case.

@bryevdv
Copy link
Member

bryevdv commented Aug 14, 2024

Thanks @cdeil !

@bryevdv bryevdv merged commit 42435cd into bokeh:branch-3.6 Aug 14, 2024
24 checks passed
@mattpap mattpap mentioned this pull request Aug 22, 2024
12 tasks
mattpap pushed a commit that referenced this pull request Aug 22, 2024
* Fix ValueError check in ColumnDataSource.patch

* Use f-string in src/bokeh/models/sources.py

* Add TestColumnDataSource::test_bad_multi_index
@mattpap mattpap modified the milestones: 3.6, 3.5.2 Aug 22, 2024
Chiemezuo pushed a commit to Chiemezuo/bokeh that referenced this pull request Aug 27, 2024
* Fix ValueError check in ColumnDataSource.patch

* Use f-string in src/bokeh/models/sources.py

* Add TestColumnDataSource::test_bad_multi_index
Copy link

github-actions bot commented Dec 4, 2024

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
python Issues that should only require updating Python code reso: completed status: accepted type: bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants