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

TYP: Narrow down types of arguments (DataFrame) #52750

Conversation

benedikt-mangold
Copy link
Contributor

Preview discussion:

We prefer using Literal["a"] | Literal["b"] instead of str. Look into the documentation what is allowed and the narrow the types down appropriately. Generally, we probably already have type definitions in pandas/_typing.py like NaPosition for the first item in the list below.

You can locate the appropriate file through searching for class DataFrame in the repository.

DataFrame methods:

  • Specifykind and na_position more precisely in sort_values (can look at sort_index, it is already done there)
  • Specify keep for nsmallest and nlargest more precisely
  • Specify join and errors in update more precisely
  • Specify na_action in applymap more precisely
  • Specify validate in merge and join more precisely
  • Specify how in to_timestamp more precisely
  • Specify orient in from_dict more precisely
  • Specify if_exists in to_gbq more precisely
  • Specify byteorder in to_stata more precisely
  • Specify engine in to_parquet more precisely
  • Specify engine in to_orc more precisely
  • Specify parser in to_xml more precisely
  • Specify method in reindex more precisely

Reviewers

@phofl @noatamir @jorisvandenbossche and @MarcoGorelli

…e argument of join and merge method

Change byteorder argument typing for to_stata method to literal, added definition in pandas/_typing.py

Change if_exists argument typing for to_gbq method to literal, added definition in pandas/_typing.py

Change orient argument typing for from_dict method to literal, added definition in pandas/_typing.py

Change how argument typing for to_timestamp method to literal, added definition in pandas/_typing.py

Change validate argument typing for merge and join methods to literal, added definition in pandas/_typing.py

Change na_action arguments typing for applymap method to literal, added definition in pandas/_typing.py

Change join and errors arguments typing for update method to litaral, added definition in pandas/_typing.py

Change keep argument typing for nlargest and nsallest to litaera, added definition in pandas/_typing.py

Specify the kind and na_position more precisely in sort_values, reusing type definitions in pandas/_typing.py
@noatamir noatamir added the Sprints Sprint Pull Requests label Apr 18, 2023
@benedikt-mangold benedikt-mangold deleted the narrow_down_types_frame_bm branch April 18, 2023 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Sprints Sprint Pull Requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

np.fix doesn't work
2 participants