While using parse_datetime() from isodatetime.py. I can "ValueError('cannot convert NaN to integer". But for same value it working sometimes

While passing a date-time string to parse_datetime(). I can see the below error.
“ValueError('cannot convert NaN to integer)”

But for same value sometime it works.

Working logs:

[2023/11/23 08:21:55.291] (1271030 /usr/bin/httpd) /usr/lib/python3/dist-packages/isodate/isodatetime.py:51 parse_datetime(): FORMAT ERROR(not all arguments converted during string formatting): 'RFE-HA datetimestring:' ('2023-11-22T06:39:26.079419+00:00',)
[2023/11/23 08:21:55.295] (1271030 /usr/bin/httpd) /usr/lib/python3/dist-packages/isodate/isodatetime.py:58 parse_datetime(): FORMAT ERROR(not all arguments converted during string formatting): 'RFE-HA timestringi s:' ('06:39:26.079419+00:00',)
[2023/11/23 08:21:55.297] (1271030 /usr/bin/httpd) /usr/lib/python3/dist-packages/isodate/isotime.py:128 parse_time(): FORMAT ERROR(not all arguments converted during string formatting): "RFE-HA groups['second']:" ('26.079419',)
[2023/11/23 08:21:55.297] (1271030 /usr/bin/httpd) /usr/lib/python3/dist-packages/isodate/isotime.py:130 parse_time(): FORMAT ERROR(not all arguments converted during string formatting): 'RFE-HA second is ' (Decimal('26.079419'),)

Non -Working Logs

[2023/11/23 08:25:01.343] (1271030 /usr/bin/httpd) /usr/lib/python3/dist-packages/isodate/isodatetime.py:51 parse_datetime(): FORMAT ERROR(not all arguments converted during string formatting): 'RFE-HA datetimestring:' ('2023-11-22T06:39:26.079419+00:00',)
[2023/11/23 08:25:01.343] (1271030 /usr/bin/httpd) /usr/lib/python3/dist-packages/isodate/isodatetime.py:58 parse_datetime(): FORMAT ERROR(not all arguments converted during string formatting): 'RFE-HA timestringi s:' ('06:39:26.079419+00:00',)
[2023/11/23 08:25:01.343] (1271030 /usr/bin/httpd) /usr/lib/python3/dist-packages/isodate/isotime.py:128 parse_time(): FORMAT ERROR(not all arguments converted during string formatting): "RFE-HA groups['second']:" ('26.079419',)
[2023/11/23 08:25:01.343] (1271030 /usr/bin/httpd) /usr/lib/python3/dist-packages/isodate/isotime.py:130 parse_time(): FORMAT ERROR(not all arguments converted during string formatting): 'RFE-HA second is ' (Decimal('NaN'),)

How to fix this issue?
It shows (Decimal(‘NaN’),)

isodatetime.py code

def parse_datetime(datetimestring):
    '''
    Parses ISO 8601 date-times into datetime.datetime objects.

    This function uses parse_date and parse_time to do the job, so it allows
    more combinations of date and time representations, than the actual
    ISO 8601:2004 standard allows.
    '''
    ilog.log("RFE-HA datetimestring:",datetimestring)
    try:
        datestring, timestring = datetimestring.split('T')
    except ValueError:
        raise ISO8601Error("ISO 8601 time designator 'T' missing. Unable to"
                           " parse datetime string %r" % datetimestring)
    tmpdate = parse_date(datestring)
    ilog.log("RFE-HA timestringi s:",timestring)
    tmptime = parse_time(timestring)
    return datetime.combine(tmpdate, tmptime)


isotime.py

def parse_time(timestring):
    '''
    Parses ISO 8601 times into datetime.time objects.

    Following ISO 8601 formats are supported:
      (as decimal separator a ',' or a '.' is allowed)
      hhmmss.ssTZD    basic complete time
      hh:mm:ss.ssTZD  extended compelte time
      hhmm.mmTZD      basic reduced accuracy time
      hh:mm.mmTZD     extended reduced accuracy time
      hh.hhTZD        basic reduced accuracy time
    TZD is the time zone designator which can be in the following format:
              no designator indicates local time zone
      Z       UTC
      +-hhmm  basic hours and minutes
      +-hh:mm extended hours and minutes
      +-hh    hours
    '''
    isotimes = build_time_regexps()
    for pattern in isotimes:
        match = pattern.match(timestring)
        if match:
            groups = match.groupdict()
            for key, value in groups.items():
                if value is not None:
                    groups[key] = value.replace(',', '.')
            tzinfo = build_tzinfo(groups['tzname'], groups['tzsign'],
                                  int(groups['tzhour'] or 0),
                                  int(groups['tzmin'] or 0))
            if 'second' in groups:
                # round to microseconds if fractional seconds are more precise
                ilog.log("RFE-HA groups['second']:",groups['second'])
                ilog.log("RFE-HA isdecimal",groups['second'].isdecimal())
                second = Decimal(groups['second']).quantize(Decimal('.000001'))
                ilog.log("RFE-HA second is ",second)
                microsecond = (second - int(second)) * int(1e6)
                # int(...) ... no rounding

Welcome!

Please create a small program that shows the problem.

Have that program parse strings that you define in the program,
do not read from a file as a first pass. This is basically a unit-test
for your parsing code.

If you cannot make that unit-test break then change the code that is seeings the NaN error and catch the exception and print the line from the file and the strings that you are passing into the parsing code when it break.

To ‘debug’ this, I would be looking at the objects that are being passed to these two functions: datetimestring and timestring

On the face of it, I would suggest that these functions are being presented with objects that they can’t handle, or maybe were not designed to handle. So the fix would seem to be to either re-code the functions so that they can handle whatever is being passed to them, or alter what is being passed to them so that they can handle the object as is.