sqltrack.notebook module

sqltrack.notebook.format_dataframe(df: DataFrame, formatting: dict | None = None, na_rep='--', relative_datetimes: bool = True, string_ellipsis: str | bool = 'left') str[source]

Returns a copy of the given Pandas DataFrame with formatting applied.

By default the following functions are applied to these the following columns (case-insensitive):

If the column name is not found in the formatting function dictionary, then the formatting function is selected based based on dtype:

Parameters:
  • formatting – overwrite the default format functions for named columns; names are case-insensitive

  • relative_datetimes – if True (default), use format_datetime_relative() for columns with datetime-like dtype, else format_datetime()

  • string_ellipsis – passed as ellipsis parameter to format_string() for columns with str-like dtype

sqltrack.notebook.format_datetime(dt: datetime, sep=' ', timespec='seconds', na_rep='--') str[source]

Return datetime in ISO format.

Parameters:
  • dt – datetime to format

  • sep – date and time separator

  • timespec – precision of the time part, one of ‘auto’, ‘hours’, ‘minutes’, ‘seconds’, ‘milliseconds’ and ‘microseconds’

  • na_rep – replacement string for NaN values

sqltrack.notebook.format_datetime_relative(dt: datetime, sep=' ', timespec='seconds', na_rep='--') str[source]

Return time since given datetime in human-readable form.

Parameters:
  • dt – datetime to format

  • sep – date and time separator

  • timespec – precision of the time part, one of ‘auto’, ‘hours’, ‘minutes’, ‘seconds’, ‘milliseconds’ and ‘microseconds’

  • na_rep – replacement string for NaN values

sqltrack.notebook.format_float(v: float, spec='.2f', na_rep='--') str[source]

Format a float value.

Parameters:
  • v – float value to format

  • spec – format spec; default ".2f"

  • na_rep – replacement string for NaN values

sqltrack.notebook.format_marked(is_marked: bool)[source]

If is_marked is True, return a gold star, else empty string.

sqltrack.notebook.format_percentage(v, mul=100, spec='.1f', na_rep='--') str[source]

Returns a percentage value with bar in background.

Parameters:
  • v – percentage value to format

  • mul – multiplicative factor for display; defaults to 100 for float values in [0,1]

  • spec – format spec; default ".1f"

  • na_rep – replacement string for NaN values

sqltrack.notebook.format_status(status: str)[source]

Return an icon for the given status.

sqltrack.notebook.format_tags(tags: dict)[source]

Return tag bubbles for the given tags.

sqltrack.notebook.format_timedelta(td: timedelta, na_rep='--') str[source]

Return a timedelta in human-readable form.

Parameters:
  • td – timedelta to format

  • na_rep – replacement string for NaN values

sqltrack.notebook.init_notebook_mode()[source]

Add the sqltrack stylesheet to the notebook.

sqltrack.notebook.textcolor(text: str, colors: Sequence[str] = None)[source]

Return a color name for the given text, based on its hash value.