panel.util package#

Submodules#

Module contents#

Various general utilities used in the panel codebase.

class panel.util.LazyHTMLSanitizer(**kwargs)[source]#

Bases: object

Wraps bleach.sanitizer.Cleaner lazily importing it on the first call to the clean method.

Methods

clean

panel.util.abbreviated_repr(value, max_length=25, natural_breaks=(',', ' '))[source]#

Returns an abbreviated repr for the supplied object. Attempts to find a natural break point while adhering to the maximum length.

panel.util.base_version(version: str) str[source]#

Extract the final release and if available pre-release (alpha, beta, release candidate) segments of a PEP440 version, defined with three components (major.minor.micro).

Useful to avoid nbsite/sphinx to display the documentation HTML title with a not so informative and rather ugly long version (e.g. 0.13.0a19.post4+g0695e214). Use it in conf.py:

version = release = base_version(package.__version__)

Return the version passed as input if no match is found with the pattern.

panel.util.datetime_as_utctimestamp(value)[source]#

Converts a datetime to a UTC timestamp used by Bokeh internally.

panel.util.decode_token(token: str, signed: bool = True) dict[str, Any][source]#

Decodes a signed or unsigned JWT token.

panel.util.flatten(line)[source]#

Flatten an arbitrarily nested sequence.

Inspired by: pd.core.common.flatten

Parameters:
linesequence

The sequence to flatten

Returns:
flattenedgenerator

Notes

This only flattens list, tuple, and dict sequences.

panel.util.full_groupby(l, key=<function <lambda>>)[source]#

Groupby implementation which does not require a prior sort

panel.util.fullpath(path: AnyStr | PathLike) str[source]#

Expanduser and then abspath for a given path.

panel.util.function_name(func) str[source]#

Returns the name of a function (or its string repr)

panel.util.indexOf(obj, objs)[source]#

Returns the index of an object in a list of objects. Unlike the list.index method this function only checks for identity not equality.

panel.util.param_name(name: str) str[source]#

Removes the integer id from a Parameterized class name.

panel.util.param_reprs(parameterized, skip=None)[source]#

Returns a list of reprs for parameters on the parameterized object. Skips default and empty values.

panel.util.parse_query(query: str) dict[str, Any][source]#

Parses a url query string, e.g. ?a=1&b=2.1&c=string, converting numeric strings to int or float types.

panel.util.prefix_length(a: str, b: str) int[source]#

Searches for the length of overlap in the starting characters of string b in a. Uses binary search if b is not already a prefix of a.

panel.util.styler_update(styler, new_df)[source]#

Updates the todo items on a pandas Styler object to apply to a new DataFrame.

Parameters:
styler: pandas.io.formats.style.Styler

Styler objects

new_df: pd.DataFrame

New DataFrame to update the styler to do items

Returns:
todos: list
panel.util.unique_iterator(seq)[source]#

Returns an iterator containing all non-duplicate elements in the input sequence.

panel.util.url_path(url: str) str[source]#

Strips the protocol and domain from a URL returning just the path.

panel.util.value_as_datetime(value)[source]#

Retrieve the value tuple as a tuple of datetime objects.