-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
WIP: Draft strawman implementation of draft strawman data frame "__dataframe__" interchange protocol for discussion #32908
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
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
465721c
wip
simonjayhawkins 2482515
Merge remote-tracking branch 'upstream/master' into protocol
simonjayhawkins 245c4f8
wip
simonjayhawkins 002ec98
wip
simonjayhawkins b54afd3
Merge remote-tracking branch 'upstream/master' into protocol
simonjayhawkins 0665e95
mypy fixup make Column.name Optional
simonjayhawkins e78d797
wip
simonjayhawkins 6ddfaf5
wip
simonjayhawkins 46f594e
isort fixup
simonjayhawkins 1ce9779
mypy fixup
simonjayhawkins 15b1622
code checks fixup
simonjayhawkins ef2e97d
test fixup
simonjayhawkins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
from typing import TYPE_CHECKING, Any, Hashable, Iterable, Sequence | ||
|
||
from pandas.wesm import dataframe as dataframe_protocol | ||
from pandas.wesm.example_dict_of_ndarray import NumPyColumn | ||
|
||
if TYPE_CHECKING: | ||
import pandas as pd | ||
|
||
|
||
class Column(NumPyColumn): | ||
""" | ||
Construct generic column from pandas Series | ||
|
||
Parameters | ||
---------- | ||
ser : pd.Series | ||
""" | ||
|
||
_ser: "pd.Series" | ||
|
||
def __init__(self, ser: "pd.Series"): | ||
self._ser = ser | ||
super().__init__(ser.name, ser.to_numpy()) | ||
|
||
|
||
class DataFrame(dataframe_protocol.DataFrame): | ||
""" | ||
Construct generic data frame from pandas DataFrame | ||
|
||
Parameters | ||
---------- | ||
df : pd.DataFrame | ||
""" | ||
|
||
_df: "pd.DataFrame" | ||
|
||
def __init__(self, df: "pd.DataFrame"): | ||
self._df = df | ||
|
||
def __str__(self) -> str: | ||
return str(self._df) | ||
|
||
def __repr__(self) -> str: | ||
return repr(self._df) | ||
|
||
def column_by_index(self, i: int) -> dataframe_protocol.Column: | ||
""" | ||
Return the column at the indicated position. | ||
""" | ||
return Column(self._df.iloc[:, i]) | ||
|
||
def column_by_name(self, key: Hashable) -> dataframe_protocol.Column: | ||
""" | ||
Return the column whose name is the indicated key. | ||
""" | ||
return Column(self._df[key]) | ||
|
||
@property | ||
def column_names(self) -> Sequence[Any]: | ||
""" | ||
Return the column names as a materialized sequence. | ||
""" | ||
return self._df.columns.to_list() | ||
|
||
@property | ||
def row_names(self) -> Sequence[Any]: | ||
""" | ||
Return the row names (if any) as a materialized sequence. It is not | ||
necessary to implement this method | ||
""" | ||
return self._df.index.to_list() | ||
|
||
def iter_column_names(self) -> Iterable[Any]: | ||
""" | ||
Return the column names as an iterable. | ||
""" | ||
return self.column_names | ||
|
||
@property | ||
def num_columns(self) -> int: | ||
""" | ||
Return the number of columns in the DataFrame. | ||
""" | ||
return self._df.shape[1] | ||
|
||
@property | ||
def num_rows(self) -> int: | ||
""" | ||
Return the number of rows in the DataFrame. | ||
""" | ||
return len(self._df) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -203,6 +203,8 @@ class TestPDApi(Base): | |
"_tslib", | ||
"_typing", | ||
"_version", | ||
"protocol", | ||
"wesm", | ||
] | ||
|
||
def test_api(self): | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
hmm, I assumed this would fail if the row names were not tuples.