Skip to content

Commit 1661deb

Browse files
authored
Merge pull request pythonnet#19 from Martin-Molinero/performance-lean-2825-decimal-csharp-to-python-float
C# decimal to Python conversion
2 parents b41e67a + 7e655ce commit 1661deb

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
@@ -485,7 +485,7 @@ def run(self):
485485

486486
setup(
487487
name="pythonnet",
488-
version="1.0.5.12",
488+
version="1.0.5.13",
489489
description=".Net and Mono integration for Python",
490490
url='https://pythonnet.github.io/',
491491
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
@@ -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;

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)