Skip to content

_get_scaling raises TypeError due to misformatted message #5545

@Icyshaman

Description

@Icyshaman

Description of your problem

When we are passing tuple (tuple is a valid data-structure for total_size) for total_size as an argument in _get_scaling() we are getting TypeError instead of ValueError even though it should raise a ValueError and this is all because of the use of old-style formatting.

Example:
When we pass a tuple containing more than one Ellipsis it should raise a ValueError but instead of that, it is throwing TypeError.

Please provide a minimal, self-contained, and reproducible example.

_get_scaling((1, 2, 5, Ellipsis, Ellipsis), (2, 3), 2)

Please provide the full traceback.
pymc.distributions.logprob._get_scaling()

Complete error traceback

Input In [1], in _get_scaling(total_size, shape, ndim)
     60     end = total_size[sep + 1 :]
     61     if Ellipsis in end:
     62         raise ValueError(
---> 63             "Double Ellipsis in `total_size` is restricted, got %r" % total_size
     64         )
     65 else:
     66     begin = total_size

TypeError: not all arguments converted during string formatting

Please provide any additional information below.
The above-mentioned issue can be solved by replacing

"Double Ellipsis in `total_size` is restricted, got %r" % total_size

in _get_scaling() by

"Double Ellipsis in `total_size` is restricted, got {}".format(total_size)

Since in present version of code it is trying to unpack the tuple elements which leads to error.

Versions and main components

  • PyMC/PyMC3 Version: 4.0.0b2
  • Aesara/Theano Version: 2.3.8
  • Python Version: 3.8.12
  • Operating system: Windows 10 Pro, Version: 21H1, OS Build: 19043.1566
  • How did you install PyMC/PyMC3: conda

Related To: #5544

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions