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

Add support for dataframes that have toPandas method #4300

Merged
merged 7 commits into from
Aug 9, 2023

Conversation

LiamConnors
Copy link
Member

@LiamConnors LiamConnors commented Jul 27, 2023

Add support for dataframes that have toPandas method

Code PR

  • I have read through the contributing notes and understand the structure of the package. In particular, if my PR modifies code of plotly.graph_objects, my modifications concern the codegen files and not generated files.
  • I have added tests (if submitting a new feature or correcting a bug) or
    modified existing tests.
  • For a new feature, I have added documentation examples in an existing or
    new tutorial notebook (please see the doc checklist as well).
  • I have added a CHANGELOG entry if fixing/changing/adding anything substantial.
  • For a new feature or a change in behaviour, I have updated the relevant docstrings in the code to describe the feature or behaviour (please see the doc checklist as well).

@LiamConnors LiamConnors requested a review from alexcjohnson July 27, 2023 20:14
CHANGELOG.md Outdated Show resolved Hide resolved
Copy link
Collaborator

@alexcjohnson alexcjohnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💃 Nice and easy 😎

LiamConnors and others added 2 commits July 28, 2023 10:23
Co-authored-by: Alex Johnson <johnson.alex.c@gmail.com>
@nicolaskruchten
Copy link
Contributor

FWIW, vaex uses .to_pandas_df() rather than .to_pandas() or .toPandas() :P

@alexcjohnson
Copy link
Collaborator

might_be_a_converter = [
    method for method in dir(df_not_pandas)
    if 'to' in method.lower()
    and 'pandas' in method.lower()
    and method.lower().index('to') < method.lower().index('pandas')
]
if might_be_a_converter:
    args["data_frame"] = getattr(df_not_pandas, might_be_a_converter[0])()

🙃 probably not, but we could add to_pandas_df explicitly as well.

Comment on lines 1434 to 1445
if not (
hasattr(df_not_pandas, "to_pandas")
or hasattr(df_not_pandas, "toPandas")
or hasattr(df_not_pandas, "to_pandas_df")
):
raise exc
args["data_frame"] = df_not_pandas.to_pandas()
if hasattr(df_not_pandas, "toPandas"):
args["data_frame"] = df_not_pandas.toPandas()
elif hasattr(df_not_pandas, "to_pandas_df"):
args["data_frame"] = df_not_pandas.to_pandas_df()
else:
args["data_frame"] = df_not_pandas.to_pandas()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big deal, but it would be a bit cleaner to invert this:

if hasattr(df_not_pandas, "toPandas"):
    args["data_frame"] = df_not_pandas.toPandas()
elif hasattr(df_not_pandas, "to_pandas_df"):
    args["data_frame"] = df_not_pandas.to_pandas_df()
elif hasattr(df_not_pandas, "to_pandas"):
    args["data_frame"] = df_not_pandas.to_pandas()
else:
    raise exc

@LiamConnors LiamConnors merged commit 00813b7 into master Aug 9, 2023
@LiamConnors LiamConnors deleted the toPandas-support branch August 9, 2023 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants