Skip to main content
Question

python error merger


bertdrenth
Contributor

I have a question, i am trying to join in a pythoncaller

 

Only i am getting this error:

BADNEWS: Cannot convert null string into an integer

(C:\code\fme\foundation\framework\util\stf\stfutil.cpp:347) class StatusInfo *__cdecl STF_stringToUInt(const class ObsoleteString &,unsigned int &)

Python Exception <AttributeError>: 'fmeobjects.FMEFeature' object has no attribute 'getAllAttributes'

Traceback (most recent call last):

 File "<string>", line 14, in input

AttributeError: 'fmeobjects.FMEFeature' object has no attribute 'getAllAttributes'

Error encountered while calling method `input'

PythonCaller_FeatureMergerReplacement (PythonFactory): PythonFactory failed to process feature

 

 

The script i am using is:

import fme
import fmeobjects
import pandas as pd
 
class FeatureMergerReplacement(object):
    def __init__(self):
        # Initialiseer de DataFrames
        self.primary_df = pd.DataFrame()
        self.secondary_df = pd.DataFrame()
 
    def input(self, feature):
        # Voeg rij toe aan primary_df
        new_row = pd.DataFrame([feature.getAllAttributes()], columns=feature.getAllAttributeNames())
        self.primary_df = pd.concat([self.primary_df, new_row], ignore_index=True)
    
    def input2(self, feature):
        # Voeg rij toe aan secondary_df
        new_row = pd.DataFrame([feature.getAllAttributes()], columns=feature.getAllAttributeNames())
        self.secondary_df = pd.concat([self.secondary_df, new_row], ignore_index=True)
 
    def close(self):
        # Voer de join-operatie uit
        self.merged_df = pd.merge(self.primary_df, self.secondary_df, on='ObservationID', how='inner')
 
        # Itereer over elke rij in het resultaat en stuur terug naar FME
        for index, row in self.merged_df.iterrows():
            feature = fmeobjects.FMEFeature()
            for col in self.merged_df.columns:
                feature.setAttribute(col, row[col])
            self.pyoutput(feature)

 

 

2 replies

david_r
Celebrity
  • January 22, 2024

Firstly, when posting Python code, can you please format it using the "Code snippet" function:

imageIt makes a big difference in readability.

Secondly, to the error message itself, there is no method called "getAllAttributes" in the FMEFeature class definition, see https://docs.safe.com/fme/html/fmepython/api/fmeobjects/_feature/fmeobjects.FMEFeature.html

You can try to use a list comprehension if you need all the values from all the attributes, e.g.:

new_row = pd.DataFrame([feature.getAttribute(x) for x in feature.getAllAttributeNames()], columns=feature.getAllAttributeNames())

 


david_r
Celebrity
  • January 22, 2024

Also, I'm not quite sure how "input2()" ever gets called?


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings