petl-developers/petl

Late-import petl.compat.numeric_types in order to allow the user to customize it

blais opened this issue · 1 comments

blais commented

The current code does not right-align numeric types when converting to text.
numeric_types is defined in petl.compat.

The following customization (via monkey-patching, yes, I know) does not work, however:

import petl.compat
petl.compat.numeric_types = petl.compat.numeric_types + (Decimal,)

because in petl/util/vis.py it is accessed like this:

from petl.compat import numeric_types, text_type

and this module gets loaded as a side-effect of importing petl.

Changing it to this - everywhere it is used - would fix the issue:

from petl import compat
...
    isinstance(..., compat.numeric_types)
...
blais commented

You could also make decimal.Decimal part of the numeric types by default.