Skip to content

np.select dtype error when assigning feature group labels #1

@KiraLiiu

Description

@KiraLiiu

When running the preprocessing pipeline (specifically in preprocess.py), the following error occurs:

Error processing configuration: Choicelist and default value do not have a common dtype: The DType <class 'numpy.dtypes._PyLongDType'> could not be promoted by <class 'numpy.dtypes.StrDType'>. This means that no common DType exists for the given inputs. For example they cannot be stored in a single array unless the dtype is `object`.

This happens at the line:

choicelist = feature_categories.keys()
df = df.assign(group=np.select(condlist, choicelist))

How to Fix

  • Explicitly convert feature_categories.keys() to a list of strings using list().
  • Explicitly set the default parameter in np.select to a string value (e.g., 'other'), ensuring all possible outputs are of the same type.

Solution

Change this code:

choicelist = feature_categories.keys()
df = df.assign(group=np.select(condlist, choicelist))

to:

choicelist = list(feature_categories.keys())
df = df.assign(group=np.select(condlist, choicelist, default='other'))

This ensures that both choicelist and default are of the same type (str), resolving the dtype error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions