Vaex Dataframe - Groupby on a calculated field - throws error

Viewed 26

I have the referenced vaex dataframe

The column "Amount_INR" is calculated using the other three attributes using the function:

def convert_curr(x,y,z):
   c = CurrencyRates()
   return c.convert(x, 'INR', y, z)

data_df_usd['Amount_INR'] = data_df_usd.apply(convert_curr,arguments=[data_df_usd.CURRENCY_CODE,data_df_usd.TOTAL_AMOUNT,data_df_usd.SUBSCRIPTION_START_DATE_DATE])

I'm trying to perform a groupby operation using the below code:

data_df_usd.groupby('CONTENTID', agg={'Revenue':vaex.agg.sum('Amount_INR')})

The code throws the below error:

RemoteTraceback: 
"""
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/vaex/scopes.py", line 113, in evaluate
    result = self[expression]
  File "/usr/local/lib/python3.7/dist-packages/vaex/scopes.py", line 198, in __getitem__
    raise KeyError("Unknown variables or column: %r" % (variable,))

**KeyError: "Unknown variables or column: 'lambda_function(CURRENCY_CODE, TOTAL_AMOUNT, SUBSCRIPTION_START_DATE_DATE)'"**

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/forex_python/converter.py", line 103, in convert
    converted_amount = rate * amount
TypeError: can't multiply sequence by non-int of type 'float'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.7/multiprocessing/pool.py", line 121, in worker
    result = (True, func(*args, **kwds))
  File "/usr/local/lib/python3.7/dist-packages/vaex/expression.py", line 1616, in _apply
    scalar_result = self.f(*[fix_type(k[i]) for k in args], **{key: value[i] for key, value in kwargs.items()})
  File "<ipython-input-7-8cc933ccf57d>", line 3, in convert_curr
    return c.convert(x, 'INR', y, z)
  File "/usr/local/lib/python3.7/dist-packages/forex_python/converter.py", line 107, in convert
    "convert requires amount parameter is of type Decimal when force_decimal=True")
forex_python.converter.DecimalFloatMismatchError: convert requires amount parameter is of type Decimal when force_decimal=True
"""


The above exception was the direct cause of the following exception:

DecimalFloatMismatchError                 Traceback (most recent call last)

<ipython-input-13-cc7b243be138> in <module>
----> 1 data_df_usd.groupby('CONTENTID', agg={'Revenue':vaex.agg.sum('Amount_INR')})
1 Answers

According to the error screenshot, this does not look like it is related to the groupby. Something is happening with the convert_curr function.

You get the error

TypeError; can't multiply sequence by non-int of type 'float'

See of you can evaluate the Amount_INR in the first place.

Related