-
Notifications
You must be signed in to change notification settings - Fork 590
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
Append common actions to the PandasClient #1464
Conversation
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.
Thanks for doing this! A few comments.
ibis/pandas/client.py
Outdated
| return list(filter(lambda t: pattern.findall(t), tables)) | ||
| return tables | ||
|
|
||
|
|
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.
Kill this newline.
ibis/pandas/client.py
Outdated
| dtypes = dict(ibis_schema_to_pandas(schema)) | ||
| df = pd.DataFrame(columns=list(dtypes.keys())).astype(dtypes) | ||
|
|
||
| self.dictionary[table_name] =df |
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.
Spacing after the = in =df
| ------- | ||
| if_exists : boolean | ||
| """ | ||
| return bool(self.list_tables(like=name)) |
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.
Could also implement this as name in self.dictionary which avoids going through every table.
ibis/pandas/tests/test_client.py
Outdated
| @@ -35,12 +35,19 @@ def test_client_table(table): | |||
| def test_client_table_repr(table): | |||
| assert 'PandasTable' in repr(table) | |||
|
|
|||
| def test_load_data(client): | |||
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.
use two newlines after function definitions.
ibis/pandas/client.py
Outdated
| df = pd.DataFrame(obj) | ||
| else: | ||
| dtypes = dict(ibis_schema_to_pandas(schema)) | ||
| df = pd.DataFrame(columns=list(dtypes.keys())).astype(dtypes) |
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.
you should be able to write this as: schema.apply_to(pd.DataFrame()).
ibis/pandas/tests/test_client.py
Outdated
|
|
||
| def test_literal(client): | ||
| lit = ibis.literal(1) | ||
| result = client.execute(lit) | ||
| assert result == 1 | ||
|
|
||
| def test_list_tables(client): |
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.
two newlines
ibis/pandas/tests/test_client.py
Outdated
|
|
||
| def test_literal(client): | ||
| lit = ibis.literal(1) | ||
| result = client.execute(lit) | ||
| assert result == 1 | ||
|
|
||
| def test_list_tables(client): | ||
| assert len(client.list_tables()) > 0 |
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.
you can implement this as assert client.list_tables()
| tables = list(self.dictionary.keys()) | ||
| if like is not None: | ||
| pattern = re.compile(like) | ||
| return list(filter(lambda t: pattern.findall(t), tables)) |
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.
Is there any particular reason you chose to use pattern.findall here instead of using re.search and checking if the match result is None? We only need to find the first matching occurrence and then terminate. Using findall will return every matching non-overlapping substring, which seems a bit wasteful.
|
Thanks for the comments. Are these failing circle tests something that this PR caused? |
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.
LGTM, except for the exists_table implementation. After that is fixed this is ready to merge.
ibis/pandas/client.py
Outdated
| ------- | ||
| if_exists : boolean | ||
| """ | ||
| return name in self.list_tables() |
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.
I still think this should be name in self.dictionary. No reason to make this unnecessarily slow.
|
@tonyfast maybe you can use this workaround https://github.com/Quansight/ibis/blob/master/ci/requirements-dev-3.6.yml#L17 until #1458 is not done. |
|
@tonyfast rebase on master and you'll be able to get past any failures that aren't related this PR. |
|
@tonyfast Looks like there's another issue, putting a PR up now to fix it. |
|
#1468 should fix these errors. |
| # kwargs is a catch all for any options required by other backends. | ||
| self.dictionary[table_name] = pd.DataFrame(obj) | ||
|
|
||
| def create_table(self, table_name, obj=None, schema=None): |
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.
Can you add a test for this?
|
@tonyfast it looks like you're out of date with master, can you rebase again? |
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.
LGTM
|
👌Thanks @cpcloud! |
|
thanks @tonyfast! |
This pull request adds list_tables, load_data, and create_table attributes for the PandasClient.