Skip to content

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

Merged
merged 3 commits into from
Jan 27, 2017
Merged

Grid Accept Dataframe #675

merged 3 commits into from
Jan 27, 2017

Conversation

Kully
Copy link
Contributor

@Kully Kully commented Jan 26, 2017

For issue: #665

Just a first pass. Haven't added tests yet - want to make sure my approach is good enough.

@Kully
Copy link
Contributor Author

Kully commented Jan 26, 2017

@theengineear Mind taking a look when you have a minute?

Copy link
Contributor

@theengineear theengineear left a comment

Choose a reason for hiding this comment

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

🐅 🐅 🐅 🐅 ! Let's see a test (in test_optional) ;)

from plotly import exceptions, utils
from plotly import exceptions, optional_imports, utils

pd = optional_imports.get_module('pandas')
Copy link
Contributor

Choose a reason for hiding this comment

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

👌

@@ -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]
Copy link
Contributor

Choose a reason for hiding this comment

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

🐄 if you need this to be a list, why not just list(columns_or_json.columns)? If you don't need this to be a list, why not just leave it as a pandas array? column_names = columns_or_json.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]
duplicate_name = utils.get_first_duplicate(column_names)
Copy link
Contributor

Choose a reason for hiding this comment

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

ah, here we go, can you not just do utils.get_first_duplicate(columns_or_json.columns)?


# create columns from dataframe
all_columns = []
for name in column_names:
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, embrace the 🦆. for name in columns_or_json.columns:.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't know why I'm afraid of Ducks...

all_columns = []
for name in column_names:
all_columns.append(Column(columns_or_json[name].tolist(), name))
self._columns = list(all_columns)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why list this? You've already instantiated a new list above all_columns = []. I don't see why an additional shallow copy is necessary?

Copy link
Contributor

@theengineear theengineear left a comment

Choose a reason for hiding this comment

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

Cool. 💃 ! Just a couple style notes in there for ya!

import pandas as pd


class Test_Dataframe_to_Grid(TestCase):
Copy link
Contributor

Choose a reason for hiding this comment

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

pep:8ball: haha class names should be like TestDataframeToGrid or something. This is like 🐍 + 🐫 or something.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Two things:

  1. What does 🐍 mean?
  2. Why would DRY be relevant here? What am I repeating?

I'm changing it to your suggested class name, just curious

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I can see why that's confusing ;__;.

I was talking about camelCase vs snake_case (hence the 🐍 and 🐫).

# Test duplicate columns
def test_duplicate_columns(self):
df = pd.DataFrame([[1, 'a'],
[2, 'b']], columns=['col_1', 'col_1'])
Copy link
Contributor

Choose a reason for hiding this comment

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

🐄 this is a weird way to break this line, I'd suggest:

df = pd.DataFrame([[1, 'a'], [2, 'b']],
                  columns=['col_1', 'col_1'])

df = pd.DataFrame([[1, 'a'],
[2, 'b']], columns=['col_1', 'col_1'])

NON_UNIQUE_COLUMN_MESSAGE = (
Copy link
Contributor

Choose a reason for hiding this comment

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

🐄 no real need for this to be a CONSTANT, imo. no biggie though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean rename it to something like pattern or message rather than ALLCAPSCONSTANT?

Copy link
Contributor

Choose a reason for hiding this comment

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

expected_message or something is what I meant.

@Kully Kully merged commit 3f56aa4 into master Jan 27, 2017
@Kully Kully deleted the grid-accept-dataframe branch January 27, 2017 15:15
@Kully Kully restored the grid-accept-dataframe branch January 27, 2017 15:15
@Kully Kully deleted the grid-accept-dataframe branch January 27, 2017 15:15
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.

2 participants