-
Notifications
You must be signed in to change notification settings - Fork 358
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
Implement DataFrame.itertuples #1960
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1960 +/- ##
=======================================
Coverage 94.63% 94.64%
=======================================
Files 49 49
Lines 10829 10861 +32
=======================================
+ Hits 10248 10279 +31
- Misses 581 582 +1
Continue to review full report at Codecov.
|
databricks/koalas/frame.py
Outdated
@@ -1436,6 +1436,103 @@ def extract_kv_from_spark_row(row): | |||
s = pd.Series(v, index=columns, name=k) | |||
yield k, s | |||
|
|||
def itertuples(self, index: bool = True, name: Optional[str] = "Pandas") -> Iterator: |
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.
For the parameter name
, shall we set it to Koalas
by default?
The name
is the name of the numedtuple.
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.
+1
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.
+1, too
@@ -186,6 +186,39 @@ def test_dataframe_multiindex_names_level(self): | |||
self.assert_eq(kdf[("X", "A")].to_pandas().columns.names, pdf[("X", "A")].columns.names) | |||
self.assert_eq(kdf[("X", "A", "Z")], pdf[("X", "A", "Z")]) | |||
|
|||
def test_itertuples(self): | |||
pdf = pd.DataFrame({"num_legs": [4, 2], "num_wings": [0, 2]}, index=["dog", "hawk"]) |
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 we add a test with multi-index column?
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.
Sounds good! Added.
It behaved as below in pandas:
>>> pdf
origin CA WA
info age children
count color
1 black 4 0
2 brown 2 2
>>> for row in pdf.itertuples():
... print(row)
...
...
Pandas(Index=(1, 'black'), _1=4, _2=0)
Pandas(Index=(2, 'brown'), _1=2, _2=2)
Looks pretty good |
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 a very trivial nit comment and #1960 (comment).
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! merging. |
Thank you! |
ref #1929