Skip to main content

Hi there,

 

I am calculating two new fields in Python caller. When I tried to set those attributes, I got an error message of "Python Exception <TypeError>: Could not convert attribute value to a supported attribute type." Here is the part of my code:

self.df2['Normalized_SAIDI_DPP2'] = self.df2['SAIDI'].apply(self.normalized_SAIDI) self.df2['Normalized_SAIFI_DPP2'] = self.df2['SAIFI'].apply(self.normalized_SAIFI)

newFeature = fmeobjects.FMEFeature()

newFeature.setAttribute('Normalized_SAIDI_DPP2',self.df2['Normalized_SAIDI_DPP2'])

Datatype of self.df2['Normalized_SAIDI_DPP2'] is string. I got an error message on the last line. Could anyone guide me where am I making the mistake?

 

I don't think self.df2['Normalized_SAIDI_DPP2'] would be a string as I am guess that you are using pandas dataframe and using .apply with returns a Series or DataFrame so therefore you will need to convert this to string.


I don't think self.df2['Normalized_SAIDI_DPP2'] would be a string as I am guess that you are using pandas dataframe and using .apply with returns a Series or DataFrame so therefore you will need to convert this to string.

Sorry I forgot to mentioned that I also converted the object into string but didn't work. My code was self.df2. Normalized_SAIDI_DPP2'. astype(str).


I don't think self.df2['Normalized_SAIDI_DPP2'] would be a string as I am guess that you are using pandas dataframe and using .apply with returns a Series or DataFrame so therefore you will need to convert this to string.

This is my updated code but still throwing the same error message:

newFeature = fmeobjects.FMEFeature() newFeature.setAttribute('Normalized_SAIDI_DPP2',self.df2['Normalized_SAIDI_DPP2'].astype(str))


I don't think self.df2['Normalized_SAIDI_DPP2'] would be a string as I am guess that you are using pandas dataframe and using .apply with returns a Series or DataFrame so therefore you will need to convert this to string.

I have also tested the following code but ended with same error

newFeature = fmeobjects.FMEFeature() newFeature.setAttribute('Normalized_SAIDI_DPP2',pd.to_numeric(self.df2['Normalized_SAIDI_DPP2']))

Error is :

Python Exception <TypeError>: Could not convert attribute value to a supported attribute type.

Traceback (most recent call last):

File "<string>", line 63, in close

TypeError: Could not convert attribute value to a supported attribute type.

NORMALIZED_DPP2 (PythonFactory): PythonFactory failed to close properly

NORMALIZED_DPP2 (PythonFactory): A fatal error has occurred. Check the logfile above for details


Hi @muhammad_yasir

I'll preface this by saying I'm not familiar with the pandas module at all.

Based on the Pandas documentation, the astype Pandas method only converts Pandas objects (the data values in the column) to the data type specified. You can verify this by using the following Python to check the type:

print(type(self.df2['Normalized_SAIDI_DPP2'].astype(str)))

The results will likely be <class 'pandas.core.series.Series'>. This is not a supported data type as the error returned from the PythonCaller indicates.

 

Perhaps you can use a for loop to access the data values within the Series object.


Hi @muhammad_yasir

I'll preface this by saying I'm not familiar with the pandas module at all.

Based on the Pandas documentation, the astype Pandas method only converts Pandas objects (the data values in the column) to the data type specified. You can verify this by using the following Python to check the type:

print(type(self.df2['Normalized_SAIDI_DPP2'].astype(str)))

The results will likely be <class 'pandas.core.series.Series'>. This is not a supported data type as the error returned from the PythonCaller indicates.

 

Perhaps you can use a for loop to access the data values within the Series object.

Yes, you are right, result is <class 'pandas.core.series.Series'> . What does that mean? Could you please also explain what do you mean by use of for loop to access the data values?


Hi @muhammad_yasir

I'll preface this by saying I'm not familiar with the pandas module at all.

Based on the Pandas documentation, the astype Pandas method only converts Pandas objects (the data values in the column) to the data type specified. You can verify this by using the following Python to check the type:

print(type(self.df2['Normalized_SAIDI_DPP2'].astype(str)))

The results will likely be <class 'pandas.core.series.Series'>. This is not a supported data type as the error returned from the PythonCaller indicates.

 

Perhaps you can use a for loop to access the data values within the Series object.

Do you mean something like this......

for i in self.df2['Normalized_SAIDI_DPP2']:

            newFeature = fmeobjects.FMEFeature()

            newFeature.setAttribute('Normalized_SAIDI_DPP2',i)  

            self.pyoutput(newFeature)

 

        pass