Skip to content

Commit

Permalink
changing brittle dtype
Browse files Browse the repository at this point in the history
  • Loading branch information
cliffckerr committed Sep 24, 2019
1 parent 6df6f81 commit 6dcb803
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion sciris/sc_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
### DATA FRAME CLASS
##############################################################################

import numbers # For numeric type
import numpy as np
from . import sc_utils as ut # Note, sc_fileio is also used, but is only imported when required to avoid a circular import
from . import sc_math as ma
Expand Down Expand Up @@ -140,7 +141,7 @@ def _sanitizecol(self, col, die=True):
def _cast(arr):
''' Attempt to cast an array to different data types, to avoid having completely numeric arrays of object type '''
output = arr
if isinstance(arr, np.ndarray) and np.can_cast(arr, np.double, casting='same_kind'): # Check that everything is a number before trying to cast to an array
if isinstance(arr, np.ndarray) and np.can_cast(arr, numbers.Number, casting='same_kind'): # Check that everything is a number before trying to cast to an array
try: # If it is, try to cast the whole array to the type of the first element
output = np.array(arr, dtype=type(arr[0]))
except: # If anything goes wrong, do nothing
Expand Down

0 comments on commit 6dcb803

Please sign in to comment.