diff --git a/stock_indicators/_cslib/__init__.py b/stock_indicators/_cslib/__init__.py index 44066285..2654615e 100644 --- a/stock_indicators/_cslib/__init__.py +++ b/stock_indicators/_cslib/__init__.py @@ -15,11 +15,9 @@ load(runtime="coreclr") import clr except Exception as e: - raise ImportError(("fail to import clr.\n" - "Stock Indicators for Python has dependency on pythonnet, which uses CLR.\n" - "Check that you have CLR installed. It supports .NET 6.0 or above.\n" - ".NET:\n\t" - "https://dotnet.microsoft.com/download/dotnet")) from e + e.add_note("Stock Indicators for Python has a dependency on CLR.\n" + "Install .NET SDK 6.0 (or newer) in your environment to add the required CLR capability.") + raise e skender_stock_indicators_dll_path = os.path.join( os.path.dirname(__file__), @@ -54,3 +52,6 @@ from Skender.Stock.Indicators import PivotPointType as CsPivotPointType from Skender.Stock.Indicators import PivotTrend as CsPivotTrend from Skender.Stock.Indicators import Match as CsMatch + +# Exceptions +from System import FormatException as CsFormatException diff --git a/stock_indicators/_cstypes/decimal.py b/stock_indicators/_cstypes/decimal.py index a1f3dc33..df1851f5 100644 --- a/stock_indicators/_cstypes/decimal.py +++ b/stock_indicators/_cstypes/decimal.py @@ -1,7 +1,7 @@ from decimal import Decimal as PyDecimal from stock_indicators._cslib import CsDecimal - +from stock_indicators._cslib import CsFormatException class Decimal: """ @@ -18,7 +18,12 @@ class Decimal: 2.5 """ def __new__(cls, decimal) -> CsDecimal: - return CsDecimal.Parse(str(decimal)) + try: + return CsDecimal.Parse(str(decimal)) + except CsFormatException as e: + e.add_note("You may be using numeric data that is incompatible with your locale environment settings.\n" + "For example, you may be using decimal points instead of commas.") + raise e def to_pydecimal(cs_decimal):