Skip to content

OrdinalEncoder: Deprecate automatically assuming lexicographic ordering #14954

Open

Description

@jnothman

Currently, using OrdinalEncoder with a string-valued feature, and without categories explicitly specifying an order, means that OrdinalEncoder will number the categories according to their lexicographic ordering.

This is not appropriate if the categories have a natural ordering (e.g. ['Green', 'Amber', 'Red']) that can be harnessed by the downstream estimator.

Rather, we should allow the user to specify categories='arbitrary' or categories='lexicographic' or something to explicitly state that lexicographic ordering is okay. When the user specifies categories='auto' for a string-valued feature, OrdinalEncoder should raise a warning along the lines of DeprecationWarning("From version 0.24, OrdinalEncoder's categories='auto' setting will not work with string-valued features, and categories='arbitrary' or an explicit category order will be required.")

Activity

  1. added
    Easy
    on Sep 11, 2019
  2. venkyyuvy commented on Sep 12, 2019

    @venkyyuvy
    Contributor

    Can I work on this?

  3. jnothman commented on Sep 12, 2019

    @jnothman
    MemberAuthor
  4. Alexrand1 commented on Sep 12, 2019

    @Alexrand1

    Can you point me to where the file is located in the repo?

  5. PyExtreme commented on Sep 22, 2019

    @PyExtreme
    Contributor

    Hi, @venkyyuvy , Are you still working on this? Since, I am also interested to contribute.

    Thanks

  6. venkyyuvy commented on Sep 22, 2019

    @venkyyuvy
    Contributor

    yes @PyExtreme
    I had raised a PR already, waiting for reviews!

  7. glemaitre commented on Nov 15, 2019

    @glemaitre
    Member

    I think that #14984, #15050, and #15396 might not be blockers for 0.22 and I would move them for 0.23.

    I think that it could be great to have a single issue (superseded #14953, #14954) to discuss the overall behaviour for categories in OneHotEncoder and OrdinalEncoder and from there having several PRs which follows the discussed proposals.

  8. yahoyoungho commented on Jul 21, 2021

    @yahoyoungho

    @glemaitre Hi, random suggestion but what the function has a parameter named mapping that takes in a dictionary with keys being strings or some type of data and values being integers (either in a float or int form)?

  9. removed
    Easy
    on Apr 5, 2026
  10. lorentzenchr commented on May 28, 2026

    @lorentzenchr
    Member

    I propose to change the behavior of categories="auto" to use the available order of the dtype if available. But no warning because OrdinaleEncoder has important use cases for unordered categoricals, see #14953 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions