8000 C# decimal to Python conversion by Martin-Molinero · Pull Request #19 · QuantConnect/pythonnet · GitHub
[go: up one dir, main page]

Skip to content

C# decimal to Python conversion #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.0.5.12
current_version = 1.0.5.13
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\.(?P<release>[a-z]+)(?P<dev>\d+))?
serialize =
{major}.{minor}.{patch}.{release}{dev}
Expand Down
2 changes: 1 addition & 1 deletion conda.recipe/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package:
name: pythonnet
version: "1.0.5.12"
version: "1.0.5.13"

build:
skip: True # [not win]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ def run(self):

setup(
name="pythonnet",
version="1.0.5.12",
version="1.0.5.13",
description=".Net and Mono integration for Python",
url='https://pythonnet.github.io/',
license='MIT',
Expand Down
2 changes: 1 addition & 1 deletion src/SharedAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
// Version Information. Keeping it simple. May need to revisit for Nuget
// See: https://codingforsmarties.wordpress.com/2016/01/21/how-to-version-assemblies-destined-for-nuget/
// AssemblyVersion can only be numeric
[assembly: AssemblyVersion("1.0.5.12")]
[assembly: AssemblyVersion("1.0.5.13")]
18 changes: 3 additions & 15 deletions src/runtime/converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ private Converter()
private static Type flagsType;
private static Type boolType;
private static Type typeType;
private static IntPtr decimalCtor;
private static IntPtr dateTimeCtor;
private static IntPtr timeSpanCtor;
private static IntPtr tzInfoCtor;
Expand All @@ -48,15 +47,9 @@ static Converter()
boolType = typeof(Boolean);
typeType = typeof(Type);

IntPtr decimalMod = Runtime.PyImport_ImportModule("decimal");
if (decimalMod == null) throw new PythonException();

IntPtr dateTimeMod = Runtime.PyImport_ImportModule("datetime");
if (dateTimeMod == null) throw new PythonException();

decimalCtor = Runtime.PyObject_GetAttrString(decimalMod, "Decimal");
if (decimalCtor == null) throw new PythonException();

dateTimeCtor = Runtime.PyObject_GetAttrString(dateTimeMod, "datetime");
if (dateTimeCtor == null) throw new PythonException();

Expand Down Expand Up @@ -280,14 +273,9 @@ internal static IntPtr ToPython(object value, Type type)
return Runtime.PyLong_FromUnsignedLongLong((ulong)value);

case TypeCode.Decimal:
string d2s = ((decimal)value).ToString(nfi);
IntPtr d2p = Runtime.PyString_FromString(d2s);
IntPtr decimalArgs = Runtime.PyTuple_New(1);
Runtime.PyTuple_SetItem(decimalArgs, 0, d2p);
var returnDecimal = Runtime.PyObject_CallObject(decimalCtor, decimalArgs);
// clean up
Runtime.XDecref(decimalArgs);
return returnDecimal;
// C# decimal to python decimal has a big impact on performance
// so we will use C# double and python float
return Runtime.PyFloat_FromDouble(decimal.ToDouble((decimal) value));

case TypeCode.DateTime:
var datetime = (DateTime)value;
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/resources/clr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Code in this module gets loaded into the main clr module.
"""

__version__ = "1.0.5.12"
__version__ = "1.0.5.13"


class clrproperty(object):
Expand Down
0