# Buggy code
def parse(intent: List[Union[Clause, str]]) -> List[Clause]:
    """
    Given the string description from a list of input Clauses (intent),
    assign the appropriate clause.attribute, clause.filter_op, and clause.value.

    Parameters
    ----------
    intent : List[Clause]
            Underspecified list of lux.Clause objects.

    Returns
    -------
    List[Clause]
            Parsed list of lux.Clause objects.
    """
    if type(intent) != list:
        raise TypeError(
            "Input intent must be a list consisting of string descriptions or lux.Clause objects."
            "\nSee more at: https://lux-api.readthedocs.io/en/latest/source/guide/intent.html"
        )
    import re

    # intent = ldf.get_context()
    new_context = []
    # checks for and converts users' string inputs into lux specifications
    for clause in intent:
        valid_values = []
        if isinstance(clause, list):
            valid_values = []
            for v in clause:
                # and v in list(ldf.columns): #TODO: Move validation check to Validator
                if type(v) is str:
                    valid_values.append(v)
            temp_spec = Clause(attribute=valid_values)
            new_context.append(temp_spec)
        elif isinstance(clause, str):
            # case where user specifies a filter
            if "=" in clause:
                eqInd = clause.index("=")
                var = clause[0:eqInd]
                if "|" in clause:
                    values = clause[eqInd + 1 :].split("|")
                    for v in values:
                        # if v in ldf.unique_values[var]: #TODO: Move validation check to Validator
                        valid_values.append(v)
                else:
                    valid_values = clause[eqInd + 1 :]
                # if var in list(ldf.columns): #TODO: Move validation check to Validator
                temp_spec = Clause(attribute=var, filter_op="=", value=valid_values)
                new_context.append(temp_spec)
            # case where user specifies a variable
            else:
                if "|" in clause:
                    values = clause.split("|")
                    for v in values:
                        # if v in list(ldf.columns): #TODO: Move validation check to Validator
                        valid_values.append(v)
                else:
                    valid_values = clause
                temp_spec = Clause(attribute=valid_values)
                new_context.append(temp_spec)
        elif type(clause) is Clause:
            new_context.append(clause)
    intent = new_context
    # ldf._intent = new_context

    for clause in intent:
        if clause.description:
            # TODO: Move validation check to Validator
            # if ((clause.description in list(ldf.columns)) or clause.description == "?"):# if clause.description in the list of attributes
            # clause.description contain ">","<". or "="
            if any(ext in [">", "<", "=", "!="] for ext in clause.description):
                # then parse it and assign to clause.attribute, clause.filter_op, clause.values
                clause.filter_op = re.findall(
                    r"/.*/|>|=|<|>=|<=|!=", clause.description
                )[0]
                split_description = clause.description.split(clause.filter_op)
                clause.attribute = split_description[0]
                clause.value = split_description[1]
                if re.match(r"^-?\d+(?:\.\d+)?$", clause.value):
                    clause.value = float(clause.value)
            elif type(clause.description) == str:
                clause.attribute = clause.description
            elif type(clause.description) == list:
                clause.attribute = clause.description
            # else: # then it is probably a value
            # 	clause.values = clause.description
    return intent


# Traceback (KeyError)
C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\formatters.py:345: UserWarning:
Unexpected error in rendering Lux widget and recommendations. Falling back to Pandas display.
Please report the following issue on Github: https://github.com/lux-org/lux/issues

C:\ProgramData\Anaconda3\lib\site-packages\lux\core\frame.py:689: UserWarning:Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\indexes\base.py", line 2898, in get_loc
return self._engine.get_loc(casted_key)
File "pandas\_libs\index.pyx", line 70, in pandas._libs.index.IndexEngine.get_loc
File "pandas\_libs\index.pyx", line 101, in pandas._libs.index.IndexEngine.get_loc
File "pandas\_libs\hashtable_class_helper.pxi", line 1032, in pandas._libs.hashtable.Int64HashTable.get_item
File "pandas\_libs\hashtable_class_helper.pxi", line 1039, in pandas._libs.hashtable.Int64HashTable.get_item
KeyError: 0

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\lux\core\frame.py", line 641, in _repr_html_
self.maintain_recs()
File "C:\ProgramData\Anaconda3\lib\site-packages\lux\core\frame.py", line 472, in maintain_recs
custom_action_collection = custom_actions(rec_df)
File "C:\ProgramData\Anaconda3\lib\site-packages\lux\action\custom.py", line 75, in custom_actions
recommendation = lux.actions.__getattr__(action_name).action(ldf)
File "C:\ProgramData\Anaconda3\lib\site-packages\lux\action\enhance.py", line 67, in enhance
vis.score = interestingness(vis, ldf)
File "C:\ProgramData\Anaconda3\lib\site-packages\lux\interestingness\interestingness.py", line 149, in interestingness
chi2_score = chi2_contingency(contingency_table)[0] * 0.9 ** (
File "C:\ProgramData\Anaconda3\lib\site-packages\scipy\stats\contingency.py", line 241, in chi2_contingency
observed = np.asarray(observed)
File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\core\_asarray.py", line 85, in asarray
return array(a, dtype, copy=False, order=order)
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\series.py", line 882, in __getitem__
return self._get_value(key)
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\series.py", line 990, in _get_value
loc = self.index.get_loc(label)
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\indexes\base.py", line 2900, in get_loc
raise KeyError(key) from err
KeyError: 0

# Fixed code
def parse(intent: List[Union[Clause, str]]) -> List[Clause]:
    """
    Given the string description from a list of input Clauses (intent),
    assign the appropriate clause.attribute, clause.filter_op, and clause.value.

    Parameters
    ----------
    intent : List[Clause]
            Underspecified list of lux.Clause objects.

    Returns
    -------
    List[Clause]
            Parsed list of lux.Clause objects.
    """
    if type(intent) != list:
        raise TypeError(
            "Input intent must be a list consisting of string descriptions or lux.Clause objects."
            "\nSee more at: https://lux-api.readthedocs.io/en/latest/source/guide/intent.html"
        )
    import re

    # intent = ldf.get_context()
    new_context = []
    # checks for and converts users' string inputs into lux specifications
    for clause in intent:
        valid_values = []
        if isinstance(clause, list):
            valid_values = []
            for v in clause:
                # and v in list(ldf.columns): #TODO: Move validation check to Validator
                if type(v) is str:
                    valid_values.append(v)
            temp_spec = Clause(attribute=valid_values)
            new_context.append(temp_spec)
        elif isinstance(clause, str):
            # case where user specifies a filter
            if "=" in clause:
                eqInd = clause.index("=")
                var = clause[0:eqInd]
                if "|" in clause:
                    values = clause[eqInd + 1 :].split("|")
                    for v in values:
                        # if v in ldf.unique_values[var]: #TODO: Move validation check to Validator
                        valid_values.append(v)
                else:
                    valid_values = clause[eqInd + 1 :]
                # if var in list(ldf.columns): #TODO: Move validation check to Validator
                temp_spec = Clause(attribute=var, filter_op="=", value=valid_values)
                new_context.append(temp_spec)
            # case where user specifies a variable
            else:
                if "|" in clause:
                    values = clause.split("|")
                    for v in values:
                        # if v in list(ldf.columns): #TODO: Move validation check to Validator
                        valid_values.append(v)
                else:
                    valid_values = clause
                temp_spec = Clause(attribute=valid_values)
                new_context.append(temp_spec)
        elif type(clause) is Clause:
            new_context.append(clause)
    intent = new_context
    # ldf._intent = new_context

    for clause in intent:
        if clause.description:
            # TODO: Move validation check to Validator
            # if ((clause.description in list(ldf.columns)) or clause.description == "?"):# if clause.description in the list of attributes
            # clause.description contain ">","<". or "="
            if type(clause.description) == str and any(
                ext in [">", "<", "=", "!="] for ext in clause.description
            ):
                # then parse it and assign to clause.attribute, clause.filter_op, clause.values
                clause.filter_op = re.findall(
                    r"/.*/|>|=|<|>=|<=|!=", clause.description
                )[0]
                split_description = clause.description.split(clause.filter_op)
                clause.attribute = split_description[0]
                clause.value = split_description[1]
                if re.match(r"^-?\d+(?:\.\d+)?$", clause.value):
                    clause.value = float(clause.value)
            elif type(clause.description) == str:
                clause.attribute = clause.description
            elif type(clause.description) == list:
                clause.attribute = clause.description
            else:  # then it is probably a value
                clause.value = clause.description
    return intent