Skip to content

Percentage.from_percent(0).__str__() raising exception due to math.log10(0)? #502

@christianparpart

Description

@christianparpart

What happened?

Raising an exception:

  File "/home/christianparpart/work/frequenz-actor-fcr-prequalifying/src/frequenz/actor/fcr_prequalifying/prequalification.py", line 299, in prequalify
    LOGGER.info("Preparing battery to %s SoC", preparation_target_soc)
  File "/usr/lib64/python3.11/logging/__init__.py", line 1489, in info
    self._log(INFO, msg, args, **kwargs)
  File "/usr/lib64/python3.11/logging/__init__.py", line 1634, in _log
    self.handle(record)
  File "/usr/lib64/python3.11/logging/__init__.py", line 1644, in handle
    self.callHandlers(record)
  File "/usr/lib64/python3.11/logging/__init__.py", line 1706, in callHandlers
    hdlr.handle(record)
  File "/usr/lib64/python3.11/logging/__init__.py", line 978, in handle
    self.emit(record)
  File "/home/christianparpart/work/frequenz-actor-fcr-prequalifying/.nox/pytest/lib/python3.11/site-packages/_pytest/logging.py", line 372, in emit
    super().emit(record)
  File "/usr/lib64/python3.11/logging/__init__.py", line 1118, in emit
    self.handleError(record)
  File "/usr/lib64/python3.11/logging/__init__.py", line 1110, in emit
    msg = self.format(record)
          ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/logging/__init__.py", line 953, in format
    return fmt.format(record)
           ^^^^^^^^^^^^^^^^^^
  File "/home/christianparpart/work/frequenz-actor-fcr-prequalifying/.nox/pytest/lib/python3.11/site-packages/_pytest/logging.py", line 136, in format
    return super().format(record)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/logging/__init__.py", line 687, in format
    record.message = record.getMessage()
                     ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/logging/__init__.py", line 377, in getMessage
    msg = msg % self.args
          ~~~~^~~~~~~~~~~
  File "/home/christianparpart/work/frequenz-actor-fcr-prequalifying/.nox/pytest/lib/python3.11/site-packages/frequenz/sdk/timeseries/_quantities.py", line 116, in __str__
    return self.__format__("")
           ^^^^^^^^^^^^^^^^^^^
  File "/home/christianparpart/work/frequenz-actor-fcr-prequalifying/.nox/pytest/lib/python3.11/site-packages/frequenz/sdk/timeseries/_quantities.py", line 167, in __format__
    exponent = math.floor(math.log10(abs_value))
                          ^^^^^^^^^^^^^^^^^^^^^
ValueError: math domain error

abs_value should be 0 in my case :)

What did you expect instead?

"0%"

Affected version(s)

v0.22.0

Affected part(s)

Actors or actors utilities (decorator, etc.) (part:actor), Core components (data structures, etc.) (part:core)

Extra information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    part:actorAffects an actor ot the actors utilities (decorator, etc.)part:coreAffects the SDK core components (data structures, etc.)priority:❓We need to figure out how soon this should be addressedtype:bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions