Skip to main content
Solved

setting new attributes

  • February 3, 2020
  • 7 replies
  • 207 views

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?

 

Best answer by debbiatsafe

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.

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

7 replies

Forum|alt.badge.img
  • 48 replies
  • February 4, 2020

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.


  • Author
  • 30 replies
  • February 4, 2020

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).


  • Author
  • 30 replies
  • February 4, 2020

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))


  • Author
  • 30 replies
  • February 11, 2020

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


debbiatsafe
Safer
Forum|alt.badge.img+21
  • Safer
  • 648 replies
  • Best Answer
  • February 12, 2020

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.


  • Author
  • 30 replies
  • February 12, 2020

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?


  • Author
  • 30 replies
  • February 12, 2020

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