@@ -108,6 +108,40 @@ class pydantic_base_model_type:
108108
109109NUMERICS = frozenset (string .digits )
110110
111+
112+ def _int_or_zero (value ):
113+ """
114+ Tries to extract some number from a string.
115+
116+ 12c becomes 12
117+ """
118+ try :
119+ return int (value )
120+ except Exception :
121+ result = []
122+ for char in value :
123+ if char in NUMERICS :
124+ result .append (char )
125+ if result :
126+ return int ('' .join (result ))
127+ return 0
128+
129+
130+ def get_semvar_as_integer (version ):
131+ """
132+ Converts:
133+
134+ '1.23.5' to 1023005
135+ """
136+ version = version .split ('.' )
137+ if len (version ) > 3 :
138+ version = version [:3 ]
139+ elif len (version ) < 3 :
140+ version .extend (['0' ] * (3 - len (version )))
141+
142+ return sum ([10 ** (i * 3 ) * _int_or_zero (v ) for i , v in enumerate (reversed (version ))])
143+
144+
111145# we used to use OrderedDictPlus when dictionaries in Python were not ordered.
112146dict_ = dict
113147
@@ -120,6 +154,10 @@ class pydantic_base_model_type:
120154
121155pypy3 = py3 and hasattr (sys , "pypy_translation_info" )
122156
157+
158+ if get_semvar_as_integer (np .__version__ ) < 1019000 :
159+ sys .exit ('The minimum required Numpy version is 1.19.0. Please upgrade your Numpy package.' )
160+
123161strings = (str , bytes ) # which are both basestring
124162unicode_type = str
125163bytes_type = bytes
@@ -321,8 +359,8 @@ def type_in_type_group(item, type_group):
321359
322360def type_is_subclass_of_type_group (item , type_group ):
323361 return isinstance (item , type_group ) \
324- or (isinstance (item , type ) and issubclass (item , type_group )) \
325- or type_in_type_group (item , type_group )
362+ or (isinstance (item , type ) and issubclass (item , type_group )) \
363+ or type_in_type_group (item , type_group )
326364
327365
328366def get_doc (doc_filename ):
0 commit comments