[Python] Trying to deepdiff throws an error on datetime

Discussão em 'Python' iniciado por Stack, Agosto 22, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to compare two very similar data structures using deepdiff. The data is loaded from two msgpack files and consists of dicts and lists containing floats, integers, strings, datetime.datetime and datetime.date instances (I have some special routines to pack/unpack datetime.date instances in msgpack in two or four bytes). The lists only consist of scalar data (i.e. no other lists or dicts).

    deepdiff is supposed to support datetime (I am using version 6.2.3 on Python 3.11.2), but comparison throws an huge number of errors:


    stringify_param was not able to get a proper repr for "2023-02-26 00:20:02+00:00". This object will be reported as None. Add instructions for this object to DeepDiff's helper.literal_eval_extended to make it work properly: invalid syntax. Maybe you meant '==' or ':=' instead of '='? (, line 1)
    ​

    Except for the value of the datetime (obviously convertable to a string), the messages are all the same. Since there are many datetime values in the file the messages never seem to end (killed the program after 15 minutes of printing error message on my macbook M1), and anyway comparing them as None will not get me the diffs I am looking for.

    I tried to cut of the datetime with

    ddiff = DeepDiff(data1, data2, truncate_datetime='second')


    which would be acceptable, but that doesn't remove the thousands of error messages.

    Is it a problem for deepdiff to use timezone aware datetime values? There is no mention of literal_eval_extended in the deepdiff documentation (or at least not found by the documentations search option).

    Continue reading...

Compartilhe esta Página