-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Grid Accept Dataframe #675
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,9 @@ | |
|
||
from requests.compat import json as _json | ||
|
||
from plotly import exceptions, utils | ||
from plotly import exceptions, optional_imports, utils | ||
|
||
pd = optional_imports.get_module('pandas') | ||
|
||
__all__ = None | ||
|
||
|
@@ -148,7 +150,21 @@ def __init__(self, columns_or_json, fid=None): | |
``` | ||
""" | ||
# TODO: verify that columns are actually columns | ||
if isinstance(columns_or_json, dict): | ||
if pd and isinstance(columns_or_json, pd.DataFrame): | ||
column_names = [name for name in columns_or_json.columns] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🐄 if you need this to be a list, why not just |
||
duplicate_name = utils.get_first_duplicate(column_names) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, here we go, can you not just do |
||
if duplicate_name: | ||
err = exceptions.NON_UNIQUE_COLUMN_MESSAGE.format(duplicate_name) | ||
raise exceptions.InputError(err) | ||
|
||
# create columns from dataframe | ||
all_columns = [] | ||
for name in column_names: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, embrace the 🦆. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't know why I'm afraid of Ducks... |
||
all_columns.append(Column(columns_or_json[name].tolist(), name)) | ||
self._columns = list(all_columns) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why |
||
self.id = '' | ||
|
||
elif isinstance(columns_or_json, dict): | ||
# check that fid is entered | ||
if fid is None: | ||
raise exceptions.PlotlyError( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌