Skip to content

Commit

Permalink
additional hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
cliffckerr committed Sep 24, 2019
1 parent bd361f4 commit c4dd14e
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions sciris/sc_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,14 @@ def _sanitizecol(self, col, die=True):

@staticmethod
def _cast(arr):
''' Attempt to cast an array to different data types '''
if ut.isnumber(arr[0]): # Check that the first element is a number before trying to cast to an array
''' 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
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]))
return output
except: # If anything goes wrong, do nothing
return arr
else:
return arr
pass
return output


def __getitem__(self, key=None, die=True, cast=True):
Expand Down

0 comments on commit c4dd14e

Please sign in to comment.