Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError when converting date greater than year 9999 #368

Closed
Roel opened this issue Nov 3, 2022 · 0 comments · Fixed by #370
Closed

ValueError when converting date greater than year 9999 #368

Roel opened this issue Nov 3, 2022 · 0 comments · Fixed by #370
Assignees
Labels
Milestone

Comments

@Roel
Copy link
Member

Roel commented Nov 3, 2022

  • PyDOV version: master
  • Python version: 3.10
  • Operating System: ubuntu

Description

When encountering a date greater than year 9999 (which is the maximum year for a date in Python), a ValueError is raised and no results are returned.

While these dates seem obvious typos to me, we could investigate whether it would be possible to ignore these values in pydov (set them to empty) and raise a warning. This would enable users to retrieve the other data in the request, which is currently not possible.

What I Did

from pydov.search.grondwatervergunning import GrondwaterVergunningSearch
from owslib.fes2 import PropertyIsEqualTo

s = GrondwaterVergunningSearch()

df = s.search(query=PropertyIsEqualTo('pkey_installatie',
              'https://www.dov.vlaanderen.be/data/installatie/2021-098492'))
print(df)
Traceback (most recent call last):
  File "/home/roel/Sideprojects/pydov/example_vergunning.py", line 8, in <module>
    df = s.search(query=PropertyIsEqualTo('pkey_installatie',
  File "/home/roel/Sideprojects/pydov/pydov/search/abstract.py", line 962, in search
    data=self._type.to_df_array(
  File "/home/roel/Sideprojects/pydov/pydov/types/abstract.py", line 618, in to_df_array
    for item in iterable:
  File "/home/roel/Sideprojects/pydov/pydov/types/abstract.py", line 435, in from_wfs
    yield (cls.from_wfs_element(feature, namespace))
  File "/home/roel/Sideprojects/pydov/pydov/types/abstract.py", line 387, in from_wfs_element
    instance.data[field['name']] = cls._parse(
  File "/home/roel/Sideprojects/pydov/pydov/types/abstract.py", line 69, in _parse
    return cls._typeconvert(text, returntype)
  File "/home/roel/Sideprojects/pydov/pydov/search/abstract.py", line 115, in _typeconvert
    return typeconvert(text)
  File "/home/roel/Sideprojects/pydov/pydov/search/abstract.py", line 98, in typeconvert
    return datetime.datetime.strptime(x, '%Y-%m-%d').date()
  File "/usr/lib/python3.10/_strptime.py", line 568, in _strptime_datetime
    tt, fraction, gmtoff_fraction = _strptime(data_string, format)
  File "/usr/lib/python3.10/_strptime.py", line 349, in _strptime
    raise ValueError("time data %r does not match format %r" %
ValueError: time data '20202-11-26' does not match format '%Y-%m-%d'
@Roel Roel added the bug label Nov 3, 2022
@Roel Roel added this to the v3.0.0 milestone Nov 3, 2022
@Roel Roel self-assigned this Nov 3, 2022
@Roel Roel closed this as completed in #370 Nov 8, 2022
@Roel Roel modified the milestones: v3.0.0, v2.2.2 Nov 8, 2022
@Roel Roel mentioned this issue Mar 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant