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

KeyError in draw_capped_multipart #2406

Closed
RUrlus opened this issue Apr 21, 2020 · 2 comments · Fixed by #2407
Closed

KeyError in draw_capped_multipart #2406

RUrlus opened this issue Apr 21, 2020 · 2 comments · Fixed by #2407
Assignees
Labels
bug something is clearly wrong here

Comments

@RUrlus
Copy link

RUrlus commented Apr 21, 2020

Hi,

A KeyError is raised in draw_capped_multipart in version 5.8.1 and 5.10.1 that is not raised in 5.8.0.

A reproducible example and full stacktrace are given below.

Error:

data = ConjectureData(VALID, 1 bytes, frozen), min_value = Timestamp('2017-01-01 00:00:00'), max_value = Timestamp('2019-01-01 00:00:00')

    def draw_capped_multipart(data, min_value, max_value):
        assert isinstance(min_value, (dt.date, dt.time, dt.datetime))
        assert type(min_value) == type(max_value)
        assert min_value <= max_value
        result = {}
        cap_low, cap_high = True, True
        duration_names_by_type = {
            dt.date: DATENAMES,
            dt.time: TIMENAMES,
            dt.datetime: DATENAMES + TIMENAMES,
        }
>       for name in duration_names_by_type[type(min_value)]:
E       KeyError: <class 'pandas._libs.tslibs.timestamps.Timestamp'>
Reproducible code:

import numpy as np
import pandas as pd

from hypothesis import given, settings
import hypothesis.strategies as hst
from hypothesis.extra import pandas as hpd

@given(
    hpd.data_frames(columns=[
        hpd.column(name='prog_start',
                   elements=hst.datetimes(
                       min_value=pd.Timestamp(2017, 1, 1),
                       max_value=pd.Timestamp(2019, 1, 1)
                   ), unique=True),
        hpd.column(name='mat_code',
                   elements=hst.integers(min_value=100)),
        hpd.column(name='SOME***@#!@%*FLoat',
                   elements=hst.floats(max_value=1000.0)
                   ),
        hpd.column(name='useful_STR',
                   elements=hst.text()
                   ),
        ], index=hpd.range_indexes(min_size=3)
    )
)
@settings(deadline=None)
def test_hypothesis_testing(df):
    pass

full stacktrace:

../../../../.pyenv/versions/3.7.5/envs/TOOLS/lib/python3.7/site-packages/hypothesis/core.py:678: in _execute_once_for_engine
    escalate_hypothesis_internal_error()
../../../../.pyenv/versions/3.7.5/envs/TOOLS/lib/python3.7/site-packages/hypothesis/core.py:649: in _execute_once_for_engine
    result = self.execute_once(data)
../../../../.pyenv/versions/3.7.5/envs/TOOLS/lib/python3.7/site-packages/hypothesis/core.py:604: in execute_once
    result = self.test_runner(data, run)
../../../../.pyenv/versions/3.7.5/envs/TOOLS/lib/python3.7/site-packages/hypothesis/executors.py:52: in default_new_style_executor
    return function(data)
../../../../.pyenv/versions/3.7.5/envs/TOOLS/lib/python3.7/site-packages/hypothesis/core.py:545: in run
    args, kwargs = data.draw(self.search_strategy)
../../../../.pyenv/versions/3.7.5/envs/TOOLS/lib/python3.7/site-packages/hypothesis/internal/conjecture/data.py:893: in draw
    return strategy.do_draw(self)
../../../../.pyenv/versions/3.7.5/envs/TOOLS/lib/python3.7/site-packages/hypothesis/strategies/_internal/collections.py:57: in do_draw
    return tuple(data.draw(e) for e in self.element_strategies)
../../../../.pyenv/versions/3.7.5/envs/TOOLS/lib/python3.7/site-packages/hypothesis/strategies/_internal/collections.py:57: in <genexpr>
    return tuple(data.draw(e) for e in self.element_strategies)
../../../../.pyenv/versions/3.7.5/envs/TOOLS/lib/python3.7/site-packages/hypothesis/internal/conjecture/data.py:888: in draw
    return strategy.do_draw(self)
../../../../.pyenv/versions/3.7.5/envs/TOOLS/lib/python3.7/site-packages/hypothesis/strategies/_internal/strategies.py:658: in do_draw
    result = self.pack(data.draw(self.mapped_strategy))
../../../../.pyenv/versions/3.7.5/envs/TOOLS/lib/python3.7/site-packages/hypothesis/internal/conjecture/data.py:888: in draw
    return strategy.do_draw(self)
../../../../.pyenv/versions/3.7.5/envs/TOOLS/lib/python3.7/site-packages/hypothesis/strategies/_internal/lazy.py:150: in do_draw
    return data.draw(self.wrapped_strategy)
../../../../.pyenv/versions/3.7.5/envs/TOOLS/lib/python3.7/site-packages/hypothesis/internal/conjecture/data.py:888: in draw
    return strategy.do_draw(self)
../../../../.pyenv/versions/3.7.5/envs/TOOLS/lib/python3.7/site-packages/hypothesis/strategies/_internal/strategies.py:658: in do_draw
    result = self.pack(data.draw(self.mapped_strategy))
../../../../.pyenv/versions/3.7.5/envs/TOOLS/lib/python3.7/site-packages/hypothesis/internal/conjecture/data.py:888: in draw
    return strategy.do_draw(self)
../../../../.pyenv/versions/3.7.5/envs/TOOLS/lib/python3.7/site-packages/hypothesis/strategies/_internal/collections.py:57: in do_draw
    return tuple(data.draw(e) for e in self.element_strategies)
../../../../.pyenv/versions/3.7.5/envs/TOOLS/lib/python3.7/site-packages/hypothesis/strategies/_internal/collections.py:57: in <genexpr>
    return tuple(data.draw(e) for e in self.element_strategies)
../../../../.pyenv/versions/3.7.5/envs/TOOLS/lib/python3.7/site-packages/hypothesis/internal/conjecture/data.py:888: in draw
    return strategy.do_draw(self)
../../../../.pyenv/versions/3.7.5/envs/TOOLS/lib/python3.7/site-packages/hypothesis/strategies/_internal/lazy.py:150: in do_draw
    return data.draw(self.wrapped_strategy)
../../../../.pyenv/versions/3.7.5/envs/TOOLS/lib/python3.7/site-packages/hypothesis/internal/conjecture/data.py:888: in draw
    return strategy.do_draw(self)
../../../../.pyenv/versions/3.7.5/envs/TOOLS/lib/python3.7/site-packages/hypothesis/strategies/_internal/lazy.py:150: in do_draw
    return data.draw(self.wrapped_strategy)
../../../../.pyenv/versions/3.7.5/envs/TOOLS/lib/python3.7/site-packages/hypothesis/internal/conjecture/data.py:888: in draw
    return strategy.do_draw(self)
../../../../.pyenv/versions/3.7.5/envs/TOOLS/lib/python3.7/site-packages/hypothesis/strategies/_internal/core.py:1722: in do_draw
    return self.definition(data.draw, *self.args, **self.kwargs)
../../../../.pyenv/versions/3.7.5/envs/TOOLS/lib/python3.7/site-packages/hypothesis/extra/pandas/impl.py:584: in just_draw_columns
    value = draw(c.elements)
../../../../.pyenv/versions/3.7.5/envs/TOOLS/lib/python3.7/site-packages/hypothesis/internal/conjecture/data.py:888: in draw
    return strategy.do_draw(self)
../../../../.pyenv/versions/3.7.5/envs/TOOLS/lib/python3.7/site-packages/hypothesis/strategies/_internal/lazy.py:150: in do_draw
    return data.draw(self.wrapped_strategy)
../../../../.pyenv/versions/3.7.5/envs/TOOLS/lib/python3.7/site-packages/hypothesis/internal/conjecture/data.py:888: in draw
    return strategy.do_draw(self)
../../../../.pyenv/versions/3.7.5/envs/TOOLS/lib/python3.7/site-packages/hypothesis/strategies/_internal/datetime.py:131: in do_draw
    result = self.draw_naive_datetime_and_combine(data, tz)
../../../../.pyenv/versions/3.7.5/envs/TOOLS/lib/python3.7/site-packages/hypothesis/strategies/_internal/datetime.py:145: in draw_naive_datetime_and_combine
    result = draw_capped_multipart(data, self.min_value, self.max_value)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

data = ConjectureData(VALID, 1 bytes, frozen), min_value = Timestamp('2017-01-01 00:00:00'), max_value = Timestamp('2019-01-01 00:00:00')

    def draw_capped_multipart(data, min_value, max_value):
        assert isinstance(min_value, (dt.date, dt.time, dt.datetime))
        assert type(min_value) == type(max_value)
        assert min_value <= max_value
        result = {}
        cap_low, cap_high = True, True
        duration_names_by_type = {
            dt.date: DATENAMES,
            dt.time: TIMENAMES,
            dt.datetime: DATENAMES + TIMENAMES,
        }
>       for name in duration_names_by_type[type(min_value)]:
E       KeyError: <class 'pandas._libs.tslibs.timestamps.Timestamp'>

../../../../.pyenv/versions/3.7.5/envs/TOOLS/lib/python3.7/site-packages/hypothesis/strategies/_internal/datetime.py:92: KeyError
========================================================================================================== short test summary info ===========================================================================================================
FAILED hypothesis_bug.py::test_hypothesis_testing - KeyError: <class 'pandas._libs.tslibs.timestamps.Timestamp'>

@Zac-HD
Copy link
Member

Zac-HD commented Apr 22, 2020

import pandas as pd
from hypothesis import given, strategies as st

@given(st.datetimes(min_value=pd.Timestamp(2017, 1, 1)))
def test_hypothesis_testing(dt):
    pass

Looks like we didn't have any tests which use datetime subclasses for the bounds to datetimes(). At least it'll be easy to fix!

@Zac-HD Zac-HD added the bug something is clearly wrong here label Apr 22, 2020
@Zac-HD Zac-HD self-assigned this Apr 22, 2020
@RUrlus
Copy link
Author

RUrlus commented Apr 24, 2020

Cool, thanks for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something is clearly wrong here
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants