File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change 2323"""
2424
2525import sys
26+ # Start temporary monkey patch to allow use of functions / constants in tskit v2.0.
27+ # The following lines can be deleted once the master tskit version has been updated
28+ import numpy as np
29+ import tskit
30+ tskit .MISSING_DATA = - 1
31+
32+
33+ class util ():
34+ @staticmethod
35+ def safe_np_int_cast (int_array , dtype , copy = False ): # Copied from v2.0 tskit/util.py
36+ if not isinstance (int_array , np .ndarray ):
37+ int_array = np .array (int_array )
38+ copy = False
39+ if int_array .size == 0 :
40+ return int_array .astype (dtype , copy = copy )
41+ try :
42+ return int_array .astype (dtype , casting = 'safe' , copy = copy )
43+ except TypeError :
44+ bounds = np .iinfo (dtype )
45+ if np .any (int_array < bounds .min ) or np .any (int_array > bounds .max ):
46+ raise OverflowError ("Cannot convert safely to {} type" .format (dtype ))
47+ if int_array .dtype .kind == 'i' and np .dtype (dtype ).kind == 'u' :
48+ casting = 'unsafe'
49+ else :
50+ casting = 'same_kind'
51+ return int_array .astype (dtype , casting = casting , copy = copy )
52+
53+
54+ tskit .util = util
55+ # End temporary monkey patch
2656
2757if sys .version_info [0 ] < 3 :
2858 raise Exception ("Python 3 only" )
You can’t perform that action at this time.
0 commit comments