Skip to content

Commit

Permalink
Enable bugbear lint (#5861)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxbro authored Oct 16, 2023
1 parent e4f4350 commit 4f24047
Show file tree
Hide file tree
Showing 58 changed files with 373 additions and 133 deletions.
4 changes: 3 additions & 1 deletion holoviews/annotators.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from .streams import BoxEdit, CurveEdit, PointDraw, PolyDraw, PolyEdit, Selection1D


def preprocess(function, current=[]):
def preprocess(function, current=None):
"""
Turns a param.depends watch call into a preprocessor method, i.e.
skips all downstream events triggered by it.
Expand All @@ -27,6 +27,8 @@ def preprocess(function, current=[]):
method which depends on a particular parameter.
(see https://github.com/pyviz/param/issues/332)
"""
if current is None:
current = []
def inner(*args, **kwargs):
self = args[0]
self.param._BATCH_WATCH = True
Expand Down
18 changes: 14 additions & 4 deletions holoviews/core/accessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class Apply(metaclass=AccessorPipelineMeta):
def __init__(self, obj, mode=None):
self._obj = obj

def __call__(self, apply_function, streams=[], link_inputs=True,
def __call__(self, apply_function, streams=None, link_inputs=True,
link_dataset=True, dynamic=None, per_element=False, **kwargs):
"""Applies a function to all (Nd)Overlay or Element objects.
Expand Down Expand Up @@ -139,6 +139,9 @@ def __call__(self, apply_function, streams=[], link_inputs=True,
from .element import Element
from .spaces import DynamicMap, HoloMap

if streams is None:
streams = []

if isinstance(self._obj, DynamicMap) and dynamic == False:
samples = tuple(d.values for d in self._obj.kdims)
if not all(samples):
Expand Down Expand Up @@ -239,22 +242,26 @@ def opts(self, *args, **kwargs):
kwargs['_method_args'] = args
return self.__call__('opts', **kwargs)

def reduce(self, dimensions=[], function=None, spreadfn=None, **kwargs):
def reduce(self, dimensions=None, function=None, spreadfn=None, **kwargs):
"""Applies a reduce function to all ViewableElement objects.
See :py:meth:`Dimensioned.opts` and :py:meth:`Apply.__call__`
for more information.
"""
if dimensions is None:
dimensions = []
kwargs['_method_args'] = (dimensions, function, spreadfn)
kwargs['per_element'] = True
return self.__call__('reduce', **kwargs)

def sample(self, samples=[], bounds=None, **kwargs):
def sample(self, samples=None, bounds=None, **kwargs):
"""Samples element values at supplied coordinates.
See :py:meth:`Dataset.sample` and :py:meth:`Apply.__call__`
for more information.
"""
if samples is None:
samples = []
kwargs['_method_args'] = (samples, bounds)
kwargs['per_element'] = True
return self.__call__('sample', **kwargs)
Expand Down Expand Up @@ -358,10 +365,13 @@ def _transform_dimension(self, kdims, vdims, dimension):
dimension = self._obj.vdims[idx]
return dimension

def _create_expression_transform(self, kdims, vdims, exclude=[]):
def _create_expression_transform(self, kdims, vdims, exclude=None):
from ..util.transform import dim
from .dimension import dimension_name

if exclude is None:
exclude = []

def _transform_expression(expression):
if dimension_name(expression.dimension) in exclude:
dimension = expression.dimension
Expand Down
4 changes: 3 additions & 1 deletion holoviews/core/boundingregion.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,10 @@ def __repr__(self):
return self.__str__()


def script_repr(self, imports=[], prefix=" "):
def script_repr(self, imports=None, prefix=" "):
# Generate import statement
if imports is None:
imports = []
cls = self.__class__.__name__
mod = self.__module__
imports.append(f"from {mod} import {cls}")
Expand Down
16 changes: 12 additions & 4 deletions holoviews/core/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ def persist(self):
self._cached = persisted
return self

def closest(self, coords=[], **kwargs):
def closest(self, coords=None, **kwargs):
"""Snaps coordinate(s) to closest coordinate in Dataset
Args:
Expand All @@ -446,6 +446,8 @@ def closest(self, coords=[], **kwargs):
Raises:
NotImplementedError: Raised if snapping is not supported
"""
if coords is None:
coords = []
if self.ndims > 1:
raise NotImplementedError("Closest method currently only "
"implemented for 1D Elements")
Expand Down Expand Up @@ -719,7 +721,7 @@ def __getitem__(self, slices):
return data


def sample(self, samples=[], bounds=None, closest=True, **kwargs):
def sample(self, samples=None, bounds=None, closest=True, **kwargs):
"""Samples values at supplied coordinates.
Allows sampling of element with a list of coordinates matching
Expand Down Expand Up @@ -751,6 +753,8 @@ def sample(self, samples=[], bounds=None, closest=True, **kwargs):
Returns:
Element containing the sampled coordinates
"""
if samples is None:
samples = []
if kwargs and samples != []:
raise Exception('Supply explicit list of samples or kwargs, not both.')
elif kwargs:
Expand Down Expand Up @@ -826,7 +830,7 @@ def sample(self, samples=[], bounds=None, closest=True, **kwargs):
return self.clone(sampled, new_type=Table, datatype=datatype)


def reduce(self, dimensions=[], function=None, spreadfn=None, **reductions):
def reduce(self, dimensions=None, function=None, spreadfn=None, **reductions):
"""Applies reduction along the specified dimension(s).
Allows reducing the values along one or more key dimension
Expand Down Expand Up @@ -854,6 +858,8 @@ def reduce(self, dimensions=[], function=None, spreadfn=None, **reductions):
Returns:
The Dataset after reductions have been applied.
"""
if dimensions is None:
dimensions = []
if any(dim in self.vdims for dim in dimensions):
raise Exception("Reduce cannot be applied to value dimensions")
function, dims = self._reduce_map(dimensions, function, reductions)
Expand Down Expand Up @@ -943,7 +949,7 @@ def aggregate(self, dimensions=None, function=None, spreadfn=None, **kwargs):
new_type=new_type, datatype=datatype)


def groupby(self, dimensions=[], container_type=HoloMap, group_type=None,
def groupby(self, dimensions=None, container_type=HoloMap, group_type=None,
dynamic=False, **kwargs):
"""Groups object by one or more dimensions
Expand All @@ -962,6 +968,8 @@ def groupby(self, dimensions=[], container_type=HoloMap, group_type=None,
Returns object of supplied container_type containing the
groups. If dynamic=True returns a DynamicMap instead.
"""
if dimensions is None:
dimensions = []
if not isinstance(dimensions, list): dimensions = [dimensions]
if not len(dimensions): dimensions = self.dimensions('key', True)
if group_type is None: group_type = type(self)
Expand Down
8 changes: 6 additions & 2 deletions holoviews/core/data/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ def add_dimension(cls, dataset, dimension, dim_pos, values, vdim):


@classmethod
def sort(cls, dataset, by=[], reverse=False):
def sort(cls, dataset, by=None, reverse=False):
if by is None:
by = []
data = dataset.data
if len(by) == 1:
sorting = cls.values(dataset, by[0]).argsort()
Expand Down Expand Up @@ -210,7 +212,9 @@ def select(cls, dataset, selection_mask=None, **selection):


@classmethod
def sample(cls, dataset, samples=[]):
def sample(cls, dataset, samples=None):
if samples is None:
samples = []
data = dataset.data
mask = False
for sample in samples:
Expand Down
4 changes: 3 additions & 1 deletion holoviews/core/data/cudf.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,9 @@ def iloc(cls, dataset, index):


@classmethod
def sort(cls, dataset, by=[], reverse=False):
def sort(cls, dataset, by=None, reverse=False):
if by is None:
by = []
cols = [dataset.get_dimension(d, strict=True).name for d in by]
return dataset.data.sort_values(by=cols, ascending=not reverse)

Expand Down
8 changes: 6 additions & 2 deletions holoviews/core/data/dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ def range(cls, dataset, dimension):
return dd.compute(column.min(), column.max())

@classmethod
def sort(cls, dataset, by=[], reverse=False):
def sort(cls, dataset, by=None, reverse=False):
if by is None:
by = []
dataset.param.warning('Dask dataframes do not support sorting')
return dataset.data

Expand Down Expand Up @@ -249,7 +251,9 @@ def unpack_scalar(cls, dataset, data):
return data.iat[0,0]

@classmethod
def sample(cls, dataset, samples=[]):
def sample(cls, dataset, samples=None):
if samples is None:
samples = []
data = dataset.data
dims = dataset.dimensions('key', label='name')
mask = None
Expand Down
8 changes: 6 additions & 2 deletions holoviews/core/data/dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,9 @@ def mask(cls, dataset, mask, mask_value=np.nan):


@classmethod
def sort(cls, dataset, by=[], reverse=False):
def sort(cls, dataset, by=None, reverse=False):
if by is None:
by = []
by = [dataset.get_dimension(d).name for d in by]
if len(by) == 1:
sorting = cls.values(dataset, by[0]).argsort()
Expand Down Expand Up @@ -338,7 +340,9 @@ def select(cls, dataset, selection_mask=None, **selection):


@classmethod
def sample(cls, dataset, samples=[]):
def sample(cls, dataset, samples=None):
if samples is None:
samples = []
mask = False
for sample in samples:
sample_mask = True
Expand Down
12 changes: 9 additions & 3 deletions holoviews/core/data/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def coords(cls, dataset, dim, ordered=False, expanded=False, edges=False):


@classmethod
def canonicalize(cls, dataset, data, data_coords=None, virtual_coords=[]):
def canonicalize(cls, dataset, data, data_coords=None, virtual_coords=None):
"""
Canonicalize takes an array of values as input and reorients
and transposes it to match the canonical format expected by
Expand All @@ -312,6 +312,8 @@ def canonicalize(cls, dataset, data, data_coords=None, virtual_coords=[]):
with a virtual integer index. This ensures these coordinates
are not simply dropped.
"""
if virtual_coords is None:
virtual_coords = []
if data_coords is None:
data_coords = dataset.dimensions('key', label='name')[::-1]

Expand Down Expand Up @@ -640,10 +642,12 @@ def mask(cls, dataset, mask, mask_val=np.nan):


@classmethod
def sample(cls, dataset, samples=[]):
def sample(cls, dataset, samples=None):
"""
Samples the gridded data into dataset of samples.
"""
if samples is None:
samples = []
ndims = dataset.ndims
dimensions = dataset.dimensions(label='name')
arrays = [dataset.data[vdim.name] for vdim in dataset.vdims]
Expand Down Expand Up @@ -741,7 +745,9 @@ def add_dimension(cls, dataset, dimension, dim_pos, values, vdim):


@classmethod
def sort(cls, dataset, by=[], reverse=False):
def sort(cls, dataset, by=None, reverse=False):
if by is None:
by = []
if not by or by in [dataset.kdims, dataset.dimensions()]:
return dataset.data
else:
Expand Down
8 changes: 6 additions & 2 deletions holoviews/core/data/ibis.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,9 @@ def dtype(cls, dataset, dimension):
dimension_type = dtype

@classmethod
def sort(cls, dataset, by=[], reverse=False):
def sort(cls, dataset, by=None, reverse=False):
if by is None:
by = []
if ibis_version() >= Version("6.0"):
import ibis
order = ibis.desc if reverse else ibis.asc
Expand Down Expand Up @@ -426,8 +428,10 @@ def select_mask(cls, dataset, selection):
return predicates

@classmethod
def sample(cls, dataset, samples=[]):
def sample(cls, dataset, samples=None):
import ibis
if samples is None:
samples = []
dims = dataset.dimensions()
data = dataset.data
if all(util.isscalar(s) or len(s) == 1 for s in samples):
Expand Down
4 changes: 3 additions & 1 deletion holoviews/core/data/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def select(cls, dataset, selection_mask=None, **selection):


@classmethod
def sample(cls, dataset, samples=[]):
def sample(cls, dataset, samples=None):
"""
Sample the Raster along one or both of its dimensions,
returning a reduced dimensionality type, which is either
Expand All @@ -248,6 +248,8 @@ def sample(cls, dataset, samples=[]):
of the sampled unit indexed by the value in the new_xaxis
tuple.
"""
if samples is None:
samples = []
if len(samples[0]) == 1:
select = {dataset.kdims[0].name: [s[0] for s in samples]}
return tuple(dataset.select(**select).columns().values())
Expand Down
8 changes: 6 additions & 2 deletions holoviews/core/data/multipath.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,9 @@ def groupby(cls, dataset, dimensions, container_type, group_type, **kwargs):
return container_type(grouped_data)

@classmethod
def sample(cls, dataset, samples=[]):
def sample(cls, dataset, samples=None):
if samples is None:
samples = []
raise NotImplementedError('Sampling operation on subpaths not supported')

@classmethod
Expand Down Expand Up @@ -348,7 +350,9 @@ def dtype(cls, dataset, dimension):
return ds.interface.dtype(ds, dimension)

@classmethod
def sort(cls, dataset, by=[], reverse=False):
def sort(cls, dataset, by=None, reverse=False):
if by is None:
by = []
by = [dataset.get_dimension(d).name for d in by]
if len(by) == 1:
sorting = cls.values(dataset, by[0], False).argsort()
Expand Down
8 changes: 6 additions & 2 deletions holoviews/core/data/pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,9 @@ def redim(cls, dataset, dimensions):


@classmethod
def sort(cls, dataset, by=[], reverse=False):
def sort(cls, dataset, by=None, reverse=False):
if by is None:
by = []
cols = [dataset.get_dimension(d, strict=True).name for d in by]

if (not isinstance(dataset.data, pd.DataFrame) or
Expand Down Expand Up @@ -364,7 +366,9 @@ def values(


@classmethod
def sample(cls, dataset, samples=[]):
def sample(cls, dataset, samples=None):
if samples is None:
samples = []
data = dataset.data
mask = None
for sample in samples:
Expand Down
Loading

0 comments on commit 4f24047

Please sign in to comment.