kanedata / ixbrl-parse

A python library for getting useful data out of ixbrl files.
https://ixbrl-parse.readthedocs.io/
MIT License
63 stars 24 forks source link

Parser fails on incorrect-formatted date objects #38

Closed jstammers closed 11 months ago

jstammers commented 11 months ago

Hello, I have some documents that contain dates that are outside of the range allowed by datetime.datetime.strprtime, e..g

<xbrli:period>
    <xbrli:startDate>0001-01-01</xbrli:startDate>
    <xbrli:endDate>0001-01-01</xbrli:endDate>
</xbrli:period>

This fails when parsing with the error ValueError: year(0) out of range. The rest of my document seems valid, so would it be possible to emit this as a warning when raise_on_error=False?

I have also seen another unrelated date issue when parsing other date strings

[09/26/23 14:23:00] WARNING  ****/site-packages/ixbrlparse/core.py:160: UserWarning: Format ixt:dateslasheu not implemented - value  warnings.py:109
                             '04/09/2023' not parsed                                                                                                                                                                             
                               ixbrlNonNumeric(   

Which suggests to me that the format isn't being inferred here. I'm not too familiar with iXBRL, but is there a way to specify the format for date strings, so that these can be correctly parsed?

drkane commented 11 months ago

Hi - thanks very much for the error report.

That's a good idea - I've now updated the raise_on_error flag so it also applies to context items, so it shouldn't raise a ValueError when parsing it. I've added a test account which seems to work, but it would be good if you could check it against your file after I've uploaded version 0.8.

I can't guarantee that this won't have knock on effects later on though - this means that instead of a context item for the ixbrlNumeric or ixbrlNonNumeric items, you'll get a string instead.


On the other date issue, the official way to extend the formats that are supported is through a plugin. However, I think it makes sense to support ixt:dateslasheu so I've added support - again it would be great if you could test that this works.

jstammers commented 11 months ago

Hi @drkane, thanks for the quick reply. I've tested your latest version and can confirm that it's working as expected. In the future, I'll look into supporting additional formats using a plugin if required.

drkane commented 11 months ago

Awesome - that's good to hear. I'll close this issue but get in touch if there's other issues.