Skip to content

Commit 58ecac3

Browse files
authored
Automatically use y as default 'text' kwarg if only two cols (#1681)
1 parent 67b7153 commit 58ecac3

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

hvplot/converter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3038,7 +3038,7 @@ def labels(self, x=None, y=None, data=None):
30383038

30393039
text = self.kwds.get('text')
30403040
if not text:
3041-
text = [c for c in data.columns if c not in (x, y)][0]
3041+
text = next((c for c in data.columns if c not in (x, y)), y)
30423042
elif text not in data.columns:
30433043
data = data.copy()
30443044
template_str = text # needed for dask lazy compute

hvplot/tests/testcharts.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,17 @@ def test_labels_format_float(self):
535535
]
536536
assert list(plot.data['label']) == ['-58.7E -34.58N', '-47.9E -15.78N', '-70.7E -33.45N']
537537

538+
def test_labels_default_y(self):
539+
edge_df = self.edge_df.copy().drop(columns=['Volume {m3}'])
540+
plot = edge_df.hvplot.labels('Longitude', 'Latitude')
541+
assert list(plot.dimensions()) == [
542+
Dimension('Longitude'),
543+
Dimension('Latitude'),
544+
Dimension('Latitude'),
545+
]
546+
assert plot.kdims == ['Longitude', 'Latitude']
547+
assert plot.vdims == ['Latitude']
548+
538549
def test_labels_by(self):
539550
plot = self.edge_df.hvplot.labels(
540551
'Longitude', 'Latitude', text='{Longitude:.1f}E {Latitude:.2f}N', by='Volume {m3}'

0 commit comments

Comments
 (0)