@@ -28,7 +28,6 @@ private Converter()
2828 private static Type flagsType ;
2929 private static Type boolType ;
3030 private static Type typeType ;
31- private static IntPtr decimalCtor ;
3231 private static IntPtr dateTimeCtor ;
3332 private static IntPtr timeSpanCtor ;
3433 private static IntPtr tzInfoCtor ;
@@ -48,15 +47,9 @@ static Converter()
4847 boolType = typeof ( Boolean ) ;
4948 typeType = typeof ( Type ) ;
5049
51- IntPtr decimalMod = Runtime . PyImport_ImportModule ( "decimal" ) ;
52- if ( decimalMod == null ) throw new PythonException ( ) ;
53-
5450 IntPtr dateTimeMod = Runtime . PyImport_ImportModule ( "datetime" ) ;
5551 if ( dateTimeMod == null ) throw new PythonException ( ) ;
5652
57- decimalCtor = Runtime . PyObject_GetAttrString ( decimalMod , "Decimal" ) ;
58- if ( decimalCtor == null ) throw new PythonException ( ) ;
59-
6053 dateTimeCtor = Runtime . PyObject_GetAttrString ( dateTimeMod , "datetime" ) ;
6154 if ( dateTimeCtor == null ) throw new PythonException ( ) ;
6255
@@ -280,14 +273,9 @@ internal static IntPtr ToPython(object value, Type type)
280273 return Runtime . PyLong_FromUnsignedLongLong ( ( ulong ) value ) ;
281274
282275 case TypeCode . Decimal :
283- string d2s = ( ( decimal ) value ) . ToString ( nfi ) ;
284- IntPtr d2p = Runtime . PyString_FromString ( d2s ) ;
285- IntPtr decimalArgs = Runtime . PyTuple_New ( 1 ) ;
286- Runtime . PyTuple_SetItem ( decimalArgs , 0 , d2p ) ;
287- var returnDecimal = Runtime . PyObject_CallObject ( decimalCtor , decimalArgs ) ;
288- // clean up
289- Runtime . XDecref ( decimalArgs ) ;
290- return returnDecimal ;
276+ // C# decimal to python decimal has a big impact on performance
277+ // so we will use C# double and python float
278+ return Runtime . PyFloat_FromDouble ( decimal . ToDouble ( ( decimal ) value ) ) ;
291279
292280 case TypeCode . DateTime :
293281 var datetime = ( DateTime ) value ;
0 commit comments