-
-
Notifications
You must be signed in to change notification settings - Fork 113
Automatically use y as default 'text' kwarg if only two cols #1681
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
base: main
Are you sure you want to change the base?
Conversation
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'm OK with this change. However the tests are broken.
Thanks I think it's because the column name has units. Going to experiment with LLM... @copilot can you fix the test by dropping the correct column? |
:'( okay maybe I don't have permissions to this repo to launch |
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.
Pull Request Overview
This PR fixes a crash in the labels
method when working with DataFrames that have only two columns by automatically using the y-axis column as the default text label.
- Fixed IndexError when no third column is available for text labels
- Added fallback logic to use y-column as text when only x and y columns exist
- Added test coverage for the two-column scenario
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
hvplot/converter.py | Added conditional logic to handle two-column DataFrames by using y as default text |
hvplot/tests/testcharts.py | Added test case to verify labels work correctly with only two columns |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
assert plot.kdims == ['Longitude', 'Latitude'] | ||
assert plot.vdims == ['Latitude'] |
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.
Just to double check, is it ok for a holoviews element to have a dimension both in the kdims and vdims?
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 think it can if you pass them in directly:
import holoviews as hv
import pandas as pd
df = pd.DataFrame({
'lat': [-34.58, -15.78, -33.45, 4.60, 10.48],
'lon': [-58.66, -47.91, -70.66, -74.08, -66.86],
})
plot = hv.Points(df, ['lon', 'lat'], 'lon')
plot.dimensions()
[Dimension('lon'), Dimension('lat'), Dimension('lon')]
This is what is now achieved here via next((c for c in data.columns if c not in (x, y)), y)
, no? @ahuang11
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.
Almost! Very close:
next((c for c in data.columns if c not in (x, y)), y)
should default to y, which is:
import holoviews as hv
import pandas as pd
df = pd.DataFrame({
'lat': [-34.58, -15.78, -33.45, 4.60, 10.48],
'lon': [-58.66, -47.91, -70.66, -74.08, -66.86],
})
plot = hv.Points(df, ['lon', 'lat'], 'lat') # lat not lon
plot.dimensions()
If df has an extra col, it'll use that:
import holoviews as hv
import pandas as pd
df = pd.DataFrame({
'lat': [-34.58, -15.78, -33.45, 4.60, 10.48],
'lon': [-58.66, -47.91, -70.66, -74.08, -66.86],
'col': ['a', 'b', 'c', 'd', 'e']
})
plot = hv.Points(df, ['lon', 'lat'], 'col')
plot.dimensions()
If only two columns, use y (this would previously crash because of
text = [c for c in data.columns if c not in (x, y)][0]
):