Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
blais opened this issue Oct 6, 2021 · 1 comment · May be fixed by #568
Open

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

blais opened this issue Oct 6, 2021 · 1 comment · May be fixed by #568

Comments

@blais
Copy link
Contributor

blais commented Oct 6, 2021

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
Copy link
Contributor Author

blais commented Oct 6, 2021

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

blais added a commit to blais/petl that referenced this issue Oct 6, 2021
…types.

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)
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant