Skip to content

Commit

Permalink
Merge pull request #115 from lsst/tickets/DM-45545
Browse files Browse the repository at this point in the history
DM-45545: Change autocast to handle numpy types
  • Loading branch information
timj authored Jan 31, 2025
2 parents 8534526 + 310599b commit 384b627
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion python/lsst/pex/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import importlib
import io
import math
import numbers
import os
import re
import shutil
Expand Down Expand Up @@ -134,9 +135,15 @@ def _autocast(x, dtype):
If appropriate, the returned value is ``x`` cast to the given type
``dtype``. If the cast cannot be performed the original value of
``x`` is returned.
Notes
-----
Will convert numpy scalar types to the standard Python equivalents.
"""
if dtype is float and isinstance(x, int):
if dtype is float and isinstance(x, numbers.Real):
return float(x)
if dtype is int and isinstance(x, numbers.Integral):
return int(x)
return x


Expand Down

0 comments on commit 384b627

Please sign in to comment.