Skip to content

Use an enum for infer_dtype return values? #29868

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

Open
TomAugspurger opened this issue Nov 26, 2019 · 4 comments
Open

Use an enum for infer_dtype return values? #29868

TomAugspurger opened this issue Nov 26, 2019 · 4 comments
Labels
Internals Related to non-user accessible pandas implementation Refactor Internal refactoring of code

Comments

@TomAugspurger
Copy link
Contributor

While working in #29799, it was quite hard to add a new return value from lib.infer_dtype. There are many places where we do something like

inferred_dtype = lib.infer_dtype(values)

if inferred_dtype == "string":
    ...

if inferred_dtype in {"datetime", "integer"}
    ...

It was hard to grep for these. Could we instead define an enum

class InferredType(enum.Enum):
    STRING: "string"
    INTEGER: "intger"
    MIXED_INTEGER: "mixed-integer"
    ...

And then return InferredType.INTEGER, and update all our checks for

if inferred_dtype == InferredType.INTEGER

I think this should be entirely backwards compatible, since we're still just returning the string.

@TomAugspurger TomAugspurger added the Refactor Internal refactoring of code label Nov 26, 2019
@jreback
Copy link
Contributor

jreback commented Nov 26, 2019

yep this is generally a good idea

@alimcmaster1
Copy link
Member

Sounds good this would be neat.

I guess the check would be

if inferred_dtype == InferredType.INTEGER.value

I can potentially take a look at this is we feel its worth doing.

@mroeschke mroeschke added Enhancement Internals Related to non-user accessible pandas implementation and removed Enhancement labels Jul 23, 2021
@theoniko
Copy link
Contributor

theoniko commented Apr 7, 2023

Hello @TomAugspurger, @mroeschke, @alimcmaster1, @jreback
Could you please have a look to #52517 and give me feeback pr is in the right direction? I am also not sure about

return value.inferred_type
?

@theoniko
Copy link
Contributor

Could somebody have a look to my pr and give feedback?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Internals Related to non-user accessible pandas implementation Refactor Internal refactoring of code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants