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

Parser raises unhandled AttributeError in parse_edtf #32

Closed
mel-mason opened this issue May 13, 2019 · 2 comments
Closed

Parser raises unhandled AttributeError in parse_edtf #32

mel-mason opened this issue May 13, 2019 · 2 comments

Comments

@mel-mason
Copy link

The parser fails with an unhandled AttributeError on the following: '7 Jun-14 Jul 1916'. It looks like the issue is that the lower and upper bounds are both lists. I'm expecting EDTFParseExceptions, but not Attribute errors.

Code to replicate: (edtf=4.0.1, python = 3.6)

import edtf
parsed_date_string = edtf.text_to_edtf('7 Jun-14 Jul 1916') # 'uuuu-06-07/1916-07-14'
parsed_date = edtf.parse_edtf(parsed_date_string) # [PartialUnspecified: 'uuuu-06-07']/[Date: '1916-07-14']
lower = parsed_date.lower_strict()

Exception thrown:

AttributeError                            Traceback (most recent call last)
~/Code/silo_indexer/.venv/lib/python3.6/site-packages/edtf/parser/parser_classes.py in _strict_date(self, lean)
    350             try:
--> 351                 r = self.lower._strict_date(lean)
    352                 if r is None:

AttributeError: 'list' object has no attribute '_strict_date'

During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)
<ipython-input-7-1bed0c797cc0> in <module>
      2 parsed_date_string = edtf.text_to_edtf('7 Jun-14 Jul 1916') # 'uuuu-06-07/1916-07-14'
      3 parsed_date = edtf.parse_edtf(parsed_date_string) # [PartialUnspecified: 'uuuu-06-07']/[Date: '1916-07-14']
----> 4 lower = parsed_date.lower_strict()

~/Code/silo_indexer/.venv/lib/python3.6/site-packages/edtf/parser/parser_classes.py in lower_strict(self)
    126 
    127     def lower_strict(self):
--> 128         return self._strict_date(lean=EARLIEST)
    129 
    130     def upper_strict(self):

~/Code/silo_indexer/.venv/lib/python3.6/site-packages/edtf/parser/parser_classes.py in _strict_date(self, lean)
    354                 return r
    355             except AttributeError: # it's a string, or no date. Result depends on the upper date
--> 356                 upper = self.upper._strict_date(LATEST)
    357                 return apply_delta(sub, upper, appsettings.DELTA_IF_UNKNOWN)
    358         else:

AttributeError: 'list' object has no attribute '_strict_date'

@ColeDCrawford
Copy link
Contributor

This should be fixed in the next v5 release:

>>> parsed_date_string = text_to_edtf('7 Jun-14 Jul 1916')
>>> parsed_date_string
'XXXX-06-07/1916-07-14'
>>> parsed_date = parse_edtf(parsed_date_string)
>>> parsed_date
Level2Interval: 'XXXX-06-07/1916-07-14'
>>> parsed_date.lower_strict()
time.struct_time(tm_year=0, tm_mon=6, tm_mday=7, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=0, tm_yday=0, tm_isdst=-1)

@ColeDCrawford ColeDCrawford mentioned this issue May 28, 2024
5 tasks
@aweakley
Copy link
Member

This is resolved by #56

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants