@@ -97,7 +97,8 @@ const NUMPY_SIMPLE_TYPES = [
9797 (" complex128" , ComplexF64),
9898]
9999
100- function init_numpy ()
100+ function numpy_rule_specs ()
101+ specs = PyConvertRuleSpec[]
101102 # simple numeric scalar types
102103 for (t, T) in NUMPY_SIMPLE_TYPES
103104 isbool = occursin (" bool" , t)
@@ -112,49 +113,72 @@ function init_numpy()
112113 rule = pyconvert_rule_numpysimplevalue {T,false} ()
113114 saferule = pyconvert_rule_numpysimplevalue {T,true} ()
114115
115- pyconvert_add_rule (saferule, name, T, Any)
116- isuint && pyconvert_add_rule (sizeof (T) ≤ sizeof (UInt) ? saferule : rule, name, UInt)
117- isuint && pyconvert_add_rule (sizeof (T) < sizeof (Int) ? saferule : rule, name, Int)
118- isint &&
119- ! isuint &&
120- pyconvert_add_rule (sizeof (T) ≤ sizeof (Int) ? saferule : rule, name, Int)
121- isint && pyconvert_add_rule (rule, name, Integer)
122- isfloat && pyconvert_add_rule (saferule, name, Float64)
123- isreal && pyconvert_add_rule (rule, name, Real)
124- iscomplex && pyconvert_add_rule (saferule, name, ComplexF64)
125- iscomplex && pyconvert_add_rule (rule, name, Complex)
126- isnumber && pyconvert_add_rule (rule, name, Number)
116+ push! (specs, (func = saferule, tname = name, type = T, scope = Any))
117+ isuint && push! (
118+ specs,
119+ (
120+ func = sizeof (T) ≤ sizeof (UInt) ? saferule : rule,
121+ tname = name,
122+ type = UInt,
123+ scope = UInt,
124+ ),
125+ )
126+ isuint && push! (
127+ specs,
128+ (
129+ func = sizeof (T) < sizeof (Int) ? saferule : rule,
130+ tname = name,
131+ type = Int,
132+ scope = Int,
133+ ),
134+ )
135+ isint && ! isuint && push! (
136+ specs,
137+ (func = sizeof (T) ≤ sizeof (Int) ? saferule : rule, tname = name, type = Int, scope = Int),
138+ )
139+ isint && push! (specs, (func = rule, tname = name, type = Integer, scope = Integer))
140+ isfloat && push! (specs, (func = saferule, tname = name, type = Float64, scope = Float64))
141+ isreal && push! (specs, (func = rule, tname = name, type = Real, scope = Real))
142+ iscomplex && push! (specs, (func = saferule, tname = name, type = ComplexF64, scope = ComplexF64))
143+ iscomplex && push! (specs, (func = rule, tname = name, type = Complex, scope = Complex))
144+ isnumber && push! (specs, (func = rule, tname = name, type = Number, scope = Number))
127145 end
128146
129147 # datetime64
130- pyconvert_add_rule (
131- pyconvert_rule_datetime64,
132- " numpy:datetime64" ,
133- DateTime64,
134- Any,
148+ push! (
149+ specs,
150+ (func = pyconvert_rule_datetime64, tname = " numpy:datetime64" , type = DateTime64, scope = Any),
135151 )
136- pyconvert_add_rule (pyconvert_rule_datetime64, " numpy:datetime64" , InlineDateTime64)
137- pyconvert_add_rule (
138- pyconvert_rule_datetime64,
139- " numpy:datetime64" ,
140- NumpyDates. DatesInstant,
152+ push! (specs, (func = pyconvert_rule_datetime64, tname = " numpy:datetime64" , type = InlineDateTime64, scope = InlineDateTime64))
153+ push! (
154+ specs,
155+ (
156+ func = pyconvert_rule_datetime64,
157+ tname = " numpy:datetime64" ,
158+ type = NumpyDates. DatesInstant,
159+ scope = NumpyDates. DatesInstant,
160+ ),
141161 )
142- pyconvert_add_rule ( pyconvert_rule_datetime64, " numpy:datetime64" , Missing, Missing)
143- pyconvert_add_rule ( pyconvert_rule_datetime64, " numpy:datetime64" , Nothing, Nothing)
162+ push! (specs, (func = pyconvert_rule_datetime64, tname = " numpy:datetime64" , type = Missing, scope = Missing) )
163+ push! (specs, (func = pyconvert_rule_datetime64, tname = " numpy:datetime64" , type = Nothing, scope = Nothing) )
144164
145165 # timedelta64
146- pyconvert_add_rule (
147- pyconvert_rule_timedelta64,
148- " numpy:timedelta64" ,
149- TimeDelta64,
150- Any,
166+ push! (
167+ specs,
168+ (func = pyconvert_rule_timedelta64, tname = " numpy:timedelta64" , type = TimeDelta64, scope = Any),
151169 )
152- pyconvert_add_rule (pyconvert_rule_timedelta64, " numpy:timedelta64" , InlineTimeDelta64)
153- pyconvert_add_rule (
154- pyconvert_rule_timedelta64,
155- " numpy:timedelta64" ,
156- NumpyDates. DatesPeriod,
170+ push! (specs, (func = pyconvert_rule_timedelta64, tname = " numpy:timedelta64" , type = InlineTimeDelta64, scope = InlineTimeDelta64))
171+ push! (
172+ specs,
173+ (
174+ func = pyconvert_rule_timedelta64,
175+ tname = " numpy:timedelta64" ,
176+ type = NumpyDates. DatesPeriod,
177+ scope = NumpyDates. DatesPeriod,
178+ ),
157179 )
158- pyconvert_add_rule (pyconvert_rule_timedelta64, " numpy:timedelta64" , Missing, Missing)
159- pyconvert_add_rule (pyconvert_rule_timedelta64, " numpy:timedelta64" , Nothing, Nothing)
180+ push! (specs, (func = pyconvert_rule_timedelta64, tname = " numpy:timedelta64" , type = Missing, scope = Missing))
181+ push! (specs, (func = pyconvert_rule_timedelta64, tname = " numpy:timedelta64" , type = Nothing, scope = Nothing))
182+
183+ return specs
160184end
0 commit comments