Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python pandas TypeError: unsupported operand type(s) for +: 'DatetimeArray' and 'str'

I have 4 classes and 1 interface, when I execute my class Fingerprinter I have this error :

TypeError: unsupported operand type(s) for +: 'DatetimeArray' and 'str'.

The problem is my function def __str__(self) in my class Fingerprinter:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

def __str__(self):
    return self._data_h_df+', '+str(self._modeCB)+', '+str(self._outputMode)

Here is my code :

class OutputMode(object):
    def __init__(self,name,startTime,intervalSeconds,timezone):
        self.__name            = name
        self.__startTime       = startTime
        self.__intervalSeconds = intervalSeconds
        self.__timezone        = timezone
    

class Fingerprinter(object):
    
    def __init__(self,data_h_df,outputMode,modeCB=CONST_MODE_CONT):
        self._data_h_df  = data_h_df
        self._modeCB     = modeCB
        self._outputMode = outputMode
    
    def _generateID(data_h_df):
        pass
    
    def run(self):
        return self._generateID(data_h_df)
    
    def __str__(self):
        return self._data_h_df+', '+str(self._modeCB)+', '+str(self._outputMode)
    
outputMode = OutputMode('EEA','06:00',8*3600,pytz.timezone('Europe/Paris'))
test = Fingerprinter(data_h_df, outputMode, CONST_MODE_CONT)
print(outputMode)
print(test)

>Solution :

Your problem is self._data_h_df is probably an array of dates (or at least not a str) and hence cannot be added to a str. Try:

def __str__(self):
    return str(self._data_h_df) + ', ' + str(self._modeCB) + ', ' + str(self._outputMode)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading