ValueError: The truth value ...

NateBI
NateBI Member
edited May 2023 in Magic ETL

Hi Folks,
I'm having an issue with a Python tile in Magic ETL , the code works on my machine (pycharm) but throws an error once in Domo (this happens often, what's the difference?)

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.al

The goal is to produce a string value surfacing the differences between two strings, which column the difference has come from, and the position of the differences within the columns.

I define a function that achieves this, then use this function in a loop, iterating through the values in two DataFrame columns, extracting the differences, and replacing a temp DataFrame's values with these outputs.

# imports
import the domomagic package into the script from domomagic import *
import pandas as pd # read data from inputs into a data frame df = read_dataframe('Filter Rows') # Function def char_position(d,p):
z = set(d)
y = set(p)
zy_diff = z.symmetric_difference(y)
list_set = list(zy_diff)
l_2 = []
for x in range(len(zy_diff)):
try:
l_2.append(f'"{list_set[x]}" - Column_One - position {d.index(list_set[x])+1} ')
except:
pass
try:
l_2.append(f'"{list_set[x]}" - Column_Two - position {p.index(list_set[x])+1}')
except:
pass
return l_2 # Getting the original DataFrame's length weh = range(len(df.index))
# Creating a temp DataFrame using the original DataFrame's length uni = pd.DataFrame({'header':'value'},index=weh) # Executing the function against to DataFrame columns # and replacing the temp values in the temp DataFrame for x in weh:
ide = str(df['Column_One'][x]).split()
pjr = str(df['Column_Two'][x]).split()
uni.iloc[x] = [char_position(ide,pjr)] write_dataframe(uni)

^ the code box is greying out everything once published - not intentional.

All help appreciated

Tagged:

Answers

  • Which version of python are you using locally and which version is your script using?

    import sys
    print(sys.version)
    

    Is it giving you a line number which is causing the error?

    **Was this post helpful? Click Agree or Like below**
    **Did this solve your problem? Accept it as a solution!**
  • NateBI
    NateBI Member
    edited May 2023

    @GrantSmith

    Version: 3.10.5

    Full error message:

    00:00:02.282 Traceback (most recent call last):
    00:00:02.282 Traceback (most recent call last):
    00:00:02.282   File "<stdin>", line 40, in <module>
    00:00:02.282   File "/home/domo/domomagic/io.py", line 48, in write_dataframe
    00:00:02.282     write_array_dict(d)
    00:00:02.283   File "/home/domo/domomagic/io.py", line 69, in write_array_dict
    00:00:02.283     write_lenstrings(path, a)
    00:00:02.283   File "/home/domo/domomagic/lenstrings.py", line 22, in write_lenstrings
    00:00:02.283     _write_string(f, s)
    00:00:02.283   File "/home/domo/domomagic/lenstrings.py", line 41, in _write_string
    00:00:02.283     if pd.isnull(value):
    00:00:02.283 ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()