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

Make Dimension.label source of truth for Dimension identity #6262

Merged
merged 7 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion holoviews/core/dimension.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def __eq__(self, other):
"Implements equals operator including sanitized comparison."

if isinstance(other, Dimension):
return self.spec == other.spec
return self.label == other.label

# For comparison to strings. Name may be sanitized.
return other in [self.name, self.label, util.dimension_sanitizer(self.name)]
Expand Down
2 changes: 1 addition & 1 deletion holoviews/core/pprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ def element_info(cls_or_slf, node, siblings, level, value_dims):
if len(node.kdims) >= 1:
info += cls_or_slf.tab + f"[{','.join(d.name for d in node.kdims)}]"
if value_dims and len(node.vdims) >= 1:
info += cls_or_slf.tab + f"({','.join(d.name for d in node.vdims)})"
info += cls_or_slf.tab + f"({','.join(d.label for d in node.vdims)})"
return level, [(level, info)]

@bothmethod
Expand Down
4 changes: 2 additions & 2 deletions holoviews/plotting/bokeh/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,10 +435,10 @@ def get_data(self, element, ranges, style):

def get_extents(self, element, ranges, range_type='combined', **kwargs):
ydim = element.get_dimension(1)
s0, s1 = ranges[ydim.name]['soft']
s0, s1 = ranges[ydim.label]['soft']
s0 = min(s0, 0) if isfinite(s0) else 0
s1 = max(s1, 0) if isfinite(s1) else 0
ranges[ydim.name]['soft'] = (s0, s1)
ranges[ydim.label]['soft'] = (s0, s1)
return super().get_extents(element, ranges, range_type)


Expand Down
2 changes: 1 addition & 1 deletion holoviews/plotting/bokeh/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ def _axis_props(self, plots, subplots, element, ranges, pos, *, dim=None,
categorical = any(self.traverse(lambda plot: plot._categorical))
if self.subcoordinate_y:
categorical = False
elif dims is not None and any(dim.name in ranges and 'factors' in ranges[dim.name] for dim in dims):
elif dims is not None and any(dim.label in ranges and 'factors' in ranges[dim.label] for dim in dims):
categorical = True
else:
categorical = any(isinstance(v, (str, bytes)) for v in (v0, v1))
Expand Down
16 changes: 8 additions & 8 deletions holoviews/plotting/bokeh/hex_tiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,16 @@ class HexTilesPlot(ColorbarPlot):

def get_extents(self, element, ranges, range_type='combined', **kwargs):
xdim, ydim = element.kdims[:2]
ranges[xdim.name]['data'] = xdim.range
ranges[ydim.name]['data'] = ydim.range
ranges[xdim.label]['data'] = xdim.range
ranges[ydim.label]['data'] = ydim.range
xd = element.cdims.get(xdim.name)
if xd and xdim.name in ranges:
ranges[xdim.name]['hard'] = xd.range
ranges[xdim.name]['soft'] = max_range([xd.soft_range, ranges[xdim.name]['soft']])
if xd and xdim.label in ranges:
ranges[xdim.label]['hard'] = xd.range
ranges[xdim.label]['soft'] = max_range([xd.soft_range, ranges[xdim.label]['soft']])
yd = element.cdims.get(ydim.name)
if yd and ydim.name in ranges:
ranges[ydim.name]['hard'] = yd.range
ranges[ydim.name]['hard'] = max_range([yd.soft_range, ranges[ydim.name]['soft']])
if yd and ydim.label in ranges:
ranges[ydim.label]['hard'] = yd.range
ranges[ydim.label]['hard'] = max_range([yd.soft_range, ranges[ydim.label]['soft']])
return super().get_extents(element, ranges, range_type)

def _hover_opts(self, element):
Expand Down
28 changes: 14 additions & 14 deletions holoviews/plotting/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def get_extents(self, element, ranges, range_type='combined', **kwargs):
kdims = element.kdims
# loop over start and end points of segments
# simultaneously in each dimension
for kdim0, kdim1 in zip([kdims[i].name for i in range(2)],
[kdims[i].name for i in range(2,4)]):
for kdim0, kdim1 in zip([kdims[i].label for i in range(2)],
[kdims[i].label for i in range(2,4)]):
new_range = {}
for kdim in [kdim0, kdim1]:
# for good measure, update ranges for both start and end kdim
Expand Down Expand Up @@ -85,10 +85,10 @@ def get_extents(self, element, ranges, range_type='combined', **kwargs):
opts = self.lookup_options(element, 'plot').options
if len(element.dimensions()) > 1 and 'spike_length' not in opts:
ydim = element.get_dimension(1)
s0, s1 = ranges[ydim.name]['soft']
s0, s1 = ranges[ydim.label]['soft']
s0 = min(s0, 0) if util.isfinite(s0) else 0
s1 = max(s1, 0) if util.isfinite(s1) else 0
ranges[ydim.name]['soft'] = (s0, s1)
ranges[ydim.label]['soft'] = (s0, s1)
proxy_dim = None
if 'spike_length' in opts or len(element.dimensions()) == 1:
proxy_dim = Dimension('proxy_dim')
Expand Down Expand Up @@ -118,12 +118,12 @@ class AreaMixin:

def get_extents(self, element, ranges, range_type='combined', **kwargs):
vdims = element.vdims[:2]
vdim = vdims[0].name
vdim = vdims[0].label
if len(vdims) > 1:
new_range = {}
for r in ranges[vdim]:
if r != 'values':
new_range[r] = util.max_range([ranges[vd.name][r] for vd in vdims])
new_range[r] = util.max_range([ranges[vd.label][r] for vd in vdims])
ranges[vdim] = new_range
else:
s0, s1 = ranges[vdim]['soft']
Expand Down Expand Up @@ -153,9 +153,9 @@ def get_extents(self, element, ranges, range_type='combined', **kwargs):
element = Bars(overlay.table(), kdims=element.kdims+overlay.kdims,
vdims=element.vdims)
for kd in overlay.kdims:
ranges[kd.name]['combined'] = overlay.range(kd)
ranges[kd.label]['combined'] = overlay.range(kd)

vdim = element.vdims[0].name
vdim = element.vdims[0].label
s0, s1 = ranges[vdim]['soft']
s0 = min(s0, 0) if util.isfinite(s0) else 0
s1 = max(s1, 0) if util.isfinite(s1) else 0
Expand Down Expand Up @@ -209,15 +209,15 @@ def _get_coords(self, element, ranges, as_string=True):
else:
if gdim.values:
gvals = gdim.values
elif ranges.get(gdim.name, {}).get('factors') is not None:
gvals = ranges[gdim.name]['factors']
elif ranges.get(gdim.label, {}).get('factors') is not None:
gvals = ranges[gdim.label]['factors']
else:
gvals = element.dimension_values(gdim, False)
gvals = np.asarray(gvals)
if xvals:
pass
elif ranges.get(xdim.name, {}).get('factors') is not None:
xvals = ranges[xdim.name]['factors']
elif ranges.get(xdim.label, {}).get('factors') is not None:
xvals = ranges[xdim.label]['factors']
else:
xvals = element.dimension_values(0, False)
xvals = np.asarray(xvals)
Expand All @@ -229,8 +229,8 @@ def _get_coords(self, element, ranges, as_string=True):
else:
if xvals:
pass
elif ranges.get(xdim.name, {}).get('factors') is not None:
xvals = ranges[xdim.name]['factors']
elif ranges.get(xdim.label, {}).get('factors') is not None:
xvals = ranges[xdim.label]['factors']
else:
xvals = element.dimension_values(0, False)
xvals = np.asarray(xvals)
Expand Down
26 changes: 13 additions & 13 deletions holoviews/plotting/mpl/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from matplotlib.dates import DateFormatter, date2num
from packaging.version import Version

from ...core.dimension import Dimension, dimension_name
from ...core.dimension import Dimension
from ...core.options import Store, abbreviated_exception
from ...core.util import (
dt64_to_dt,
Expand All @@ -23,7 +23,7 @@
from ...util.transform import dim
from ..mixins import AreaMixin, BarsMixin, SpikesMixin
from ..plot import PlotSelector
from ..util import compute_sizes, get_min_distance, get_sideplot_ranges
from ..util import compute_sizes, dim_range_key, get_min_distance, get_sideplot_ranges
from .element import ColorbarPlot, ElementPlot, LegendPlot
from .path import PathPlot
from .plot import AdjoinedPlot, mpl_rc_context
Expand Down Expand Up @@ -396,10 +396,10 @@ def _compute_ticks(self, element, edges, widths, lims):

def get_extents(self, element, ranges, range_type='combined', **kwargs):
ydim = element.get_dimension(1)
s0, s1 = ranges[ydim.name]['soft']
s0, s1 = ranges[ydim.label]['soft']
s0 = min(s0, 0) if isfinite(s0) else 0
s1 = max(s1, 0) if isfinite(s1) else 0
ranges[ydim.name]['soft'] = (s0, s1)
ranges[ydim.label]['soft'] = (s0, s1)
return super().get_extents(element, ranges, range_type)

def _process_axsettings(self, hist, lims, ticks):
Expand Down Expand Up @@ -644,11 +644,11 @@ def update_handles(self, key, axis, element, ranges, style):
paths = self.handles['artist']
(xs, ys), style, _ = self.get_data(element, ranges, style)
xdim, ydim = element.dimensions()[:2]
if 'factors' in ranges.get(xdim.name, {}):
factors = list(ranges[xdim.name]['factors'])
if 'factors' in ranges.get(xdim.label, {}):
factors = list(ranges[xdim.label]['factors'])
xs = [factors.index(x) for x in xs if x in factors]
if 'factors' in ranges.get(ydim.name, {}):
factors = list(ranges[ydim.name]['factors'])
if 'factors' in ranges.get(ydim.label, {}):
factors = list(ranges[ydim.label]['factors'])
ys = [factors.index(y) for y in ys if y in factors]
paths.set_offsets(np.column_stack([xs, ys]))
if 's' in style:
Expand Down Expand Up @@ -752,7 +752,7 @@ def _get_magnitudes(self, element, style, ranges):
magnitudes = mag_dim.apply(element, flat=True)
else:
magnitudes = element.dimension_values(mag_dim)
_, max_magnitude = ranges[dimension_name(mag_dim)]['combined']
_, max_magnitude = ranges[dim_range_key(mag_dim)]['combined']
if self.normalize_lengths and max_magnitude != 0:
magnitudes = magnitudes / max_magnitude
else:
Expand Down Expand Up @@ -873,8 +873,8 @@ def _get_values(self, element, ranges):
dimensions = [kdims[0], None, stack_dim]
if stack_dim.values:
stack_order = stack_dim.values
elif stack_dim in ranges and ranges[stack_dim.name].get('factors'):
stack_order = ranges[stack_dim]['factors']
elif stack_dim in ranges and ranges[stack_dim.label].get('factors'):
stack_order = ranges[stack_dim.label]['factors']
else:
stack_order = element.dimension_values(1, False)
stack_order = list(stack_order)
Expand Down Expand Up @@ -1042,15 +1042,15 @@ def _create_bars(self, axis, element, ranges, style):
legend_opts.update(**leg_spec)
axis.legend(title=title, **legend_opts)

x_range = ranges[gdim.name]["data"]
x_range = ranges[gdim.label]["data"]
if continuous and not is_dt:
if style.get('align', 'center') == 'center':
left_multiplier = 0.5
right_multiplier = 0.5
else:
left_multiplier = 0
right_multiplier = 1
ranges[gdim.name]["data"] = (
ranges[gdim.label]["data"] = (
x_range[0] - width * left_multiplier,
x_range[1] + width * right_multiplier
)
Expand Down
4 changes: 2 additions & 2 deletions holoviews/plotting/mpl/graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ def get_data(self, element, ranges, style):

if self.directed:
xdim, ydim = element.nodes.kdims[:2]
x_range = ranges[xdim.name]['combined']
y_range = ranges[ydim.name]['combined']
x_range = ranges[xdim.label]['combined']
y_range = ranges[ydim.label]['combined']
arrow_len = np.hypot(y_range[1]-y_range[0], x_range[1]-x_range[0])*self.arrowhead_length
paths = get_directed_graph_paths(element, arrow_len)
else:
Expand Down
4 changes: 2 additions & 2 deletions holoviews/plotting/mpl/sankey.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def get_extents(self, element, ranges, range_type='combined', **kwargs):
return element.nodes.extents
xdim, ydim = element.nodes.kdims[:2]
xpad = .05 if self.label_index is None else 0.25
x0, x1 = ranges[xdim.name][range_type]
y0, y1 = ranges[ydim.name][range_type]
x0, x1 = ranges[xdim.label][range_type]
y0, y1 = ranges[ydim.label][range_type]
xdiff = (x1-x0)
ydiff = (y1-y0)
if self.label_position == 'right':
Expand Down
2 changes: 1 addition & 1 deletion holoviews/plotting/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ def _compute_group_range(cls, group, elements, ranges, framewise,

# Compute dimension normalization
for el_dim in el.dimensions('ranges'):
dim_name = el_dim.name
dim_name = el_dim.label
if dim_name in prev_ranges and not framewise:
continue
data_range = data_ranges[(el, el_dim)]
Expand Down
2 changes: 2 additions & 0 deletions holoviews/plotting/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,8 @@ def _render_ipywidget(self, plot):
from IPython.display import display
display(data, raw=True)
return {'text/html': '<div style="display: none"></div>'}, {}
elif config.comms == 'colab':
load_notebook(config.inline)
philippjfr marked this conversation as resolved.
Show resolved Hide resolved
philippjfr marked this conversation as resolved.
Show resolved Hide resolved
return data, {}

def static_html(self, obj, fmt=None, template=None):
Expand Down
2 changes: 1 addition & 1 deletion holoviews/plotting/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,7 @@ def dim_range_key(eldim):
if dim_name.startswith("dim('") and dim_name.endswith("')"):
dim_name = dim_name[5:-2]
else:
dim_name = eldim.name
dim_name = eldim.label
return dim_name


Expand Down
Loading