Skip to content

Commit 1f7d308

Browse files
Martin-MolineroAlexCatarino
authored andcommitted
C# decimal conversion
- C# decimal conversion will use C# double and python float due to the big performance impact of converting C# decimal to python decimal.
1 parent c5019a3 commit 1f7d308

File tree

6 files changed

+8
-20
lines changed

6 files changed

+8
-20
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 1.0.5.12
2+
current_version = 1.0.5.13
33
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\.(?P<release>[a-z]+)(?P<dev>\d+))?
44
serialize =
55
{major}.{minor}.{patch}.{release}{dev}

conda.recipe/meta.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package:
22
name: pythonnet
3-
version: "1.0.5.12"
3+
version: "1.0.5.13"
44

55
build:
66
skip: True # [not win]

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ def run(self):
492492

493493
setup(
494494
name="pythonnet",
495-
version="1.0.5.12",
495+
version="1.0.5.13",
496496
description=".Net and Mono integration for Python",
497497
url='https://pythonnet.github.io/',
498498
license='MIT',

src/SharedAssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@
2525
// Version Information. Keeping it simple. May need to revisit for Nuget
2626
// See: https://codingforsmarties.wordpress.com/2016/01/21/how-to-version-assemblies-destined-for-nuget/
2727
// AssemblyVersion can only be numeric
28-
[assembly: AssemblyVersion("1.0.5.12")]
28+
[assembly: AssemblyVersion("1.0.5.13")]

src/runtime/converter.cs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ private Converter()
2929
private static Type flagsType;
3030
private static Type boolType;
3131
private static Type typeType;
32-
private static IntPtr decimalCtor;
3332
private static IntPtr dateTimeCtor;
3433
private static IntPtr timeSpanCtor;
3534
private static IntPtr tzInfoCtor;
@@ -49,15 +48,9 @@ static Converter()
4948
boolType = typeof(Boolean);
5049
typeType = typeof(Type);
5150

52-
IntPtr decimalMod = Runtime.PyImport_ImportModule("decimal");
53-
if (decimalMod == null) throw new PythonException();
54-
5551
IntPtr dateTimeMod = Runtime.PyImport_ImportModule("datetime");
5652
if (dateTimeMod == null) throw new PythonException();
5753

58-
decimalCtor = Runtime.PyObject_GetAttrString(decimalMod, "Decimal");
59-
if (decimalCtor == null) throw new PythonException();
60-
6154
dateTimeCtor = Runtime.PyObject_GetAttrString(dateTimeMod, "datetime");
6255
if (dateTimeCtor == null) throw new PythonException();
6356

@@ -281,14 +274,9 @@ internal static IntPtr ToPython(object value, Type type)
281274
return Runtime.PyLong_FromUnsignedLongLong((ulong)value);
282275

283276
case TypeCode.Decimal:
284-
string d2s = ((decimal)value).ToString(nfi);
285-
IntPtr d2p = Runtime.PyString_FromString(d2s);
286-
IntPtr decimalArgs = Runtime.PyTuple_New(1);
287-
Runtime.PyTuple_SetItem(decimalArgs, 0, d2p);
288-
var returnDecimal = Runtime.PyObject_CallObject(decimalCtor, decimalArgs);
289-
// clean up
290-
Runtime.XDecref(decimalArgs);
291-
return returnDecimal;
277+
// C# decimal to python decimal has a big impact on performance
278+
// so we will use C# double and python float
279+
return Runtime.PyFloat_FromDouble(decimal.ToDouble((decimal) value));
292280

293281
case TypeCode.DateTime:
294282
var datetime = (DateTime)value;

src/runtime/resources/clr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Code in this module gets loaded into the main clr module.
33
"""
44

5-
__version__ = "1.0.5.12"
5+
__version__ = "1.0.5.13"
66

77

88
class clrproperty(object):

0 commit comments

Comments
 (0)