Skip to content

issue converting dataset to list[Quote], volume CsDecimal "The input string '1.8e-05' was not in a correct format" #428

@tobiaswuerth

Description

@tobiaswuerth

What happened?

I'm trying to load the dataset as described:

from stock_indicators import Quote, indicators

quotes = [ 
  Quote(date, open, high, low, close, volume) 
    for date, open, high, low, close, volume 
    in zip(df['timestamp'],
           df['open'], 
           df['high'], 
           df['low'],
           df['close'], 
           df['volume'])]

and get the exception:


FormatException Traceback (most recent call last)
Cell In[100], line 4
1 from stock_indicators import Quote, indicators
3 quotes = [
----> 4 Quote(date, open, high, low, close, volume)
5 for date, open, high, low, close, volume
6 in zip(df['timestamp'],
7 df['open'],
8 df['high'],
9 df['low'],
10 df['close'],
11 df['volume'])]

File .venv\Lib\site-packages\stock_indicators\indicators\common\quote.py:66, in _Quote.init(self, date, open, high, low, close, volume)
64 self.low: Decimal = low if low else 0
65 self.close: Decimal = close if close else 0
---> 66 self.volume: Decimal = volume if volume else 0

File .venv\Lib\site-packages\stock_indicators\indicators\common\quote.py:48, in _set_volume(quote, value)
47 def _set_volume(quote, value):
---> 48 quote.Volume = CsDecimal(value)

File .venv\Lib\site-packages\stock_indicators_cstypes\decimal.py:22, in Decimal.new(cls, decimal)
21 def new(cls, decimal) -> CsDecimal:
---> 22 return CsDecimal.Parse(str(decimal), CsCultureInfo.InvariantCulture)

FormatException: The input string '1.8e-05' was not in a correct format.
at System.Number.ThrowFormatException[TChar](ReadOnlySpan1 value) at System.Decimal.Parse(String s, IFormatProvider provider) at InvokeStub_Decimal.Parse(Object, Span1)
at System.Reflection.MethodBaseInvoker.InvokeWithFewArgs(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

Minimal code to reproduce standalone:

from stock_indicators._cstypes import Decimal as CsDecimal
CsDecimal(1.8e-05)
CsDecimal(0.000018)

using version: stock_indicators-1.3.4-py3-none-any.whl on Python 3.12.8

... not sure if I'm doing something wrong but I feel like this should work?
Thanks

Metadata

Metadata

Labels

No labels
No labels

Type

Projects

Status

✅ Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions