-
Notifications
You must be signed in to change notification settings - Fork 367
Add column axis in ks.concat #1349
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
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
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 |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
| import itertools | ||
|
|
||
| import pandas as pd | ||
|
|
||
|
|
@@ -92,10 +93,6 @@ def test_concat(self): | |
|
|
||
| self.assertRaisesRegex(ValueError, "All objects passed", lambda: ks.concat([None, None])) | ||
|
|
||
| self.assertRaisesRegex( | ||
| NotImplementedError, "axis should be either 0 or", lambda: ks.concat([kdf, kdf], axis=1) | ||
| ) | ||
|
|
||
| pdf3 = pdf.copy() | ||
| kdf3 = kdf.copy() | ||
|
|
||
|
|
@@ -128,3 +125,75 @@ def test_concat(self): | |
| r"Only can inner \(intersect\) or outer \(union\) join the other axis.", | ||
| lambda: ks.concat([kdf, kdf4], join=""), | ||
| ) | ||
|
|
||
| self.assertRaisesRegex( | ||
| ValueError, | ||
| r"Only can inner \(intersect\) or outer \(union\) join the other axis.", | ||
| lambda: ks.concat([kdf, kdf4], join="", axis=1), | ||
| ) | ||
|
|
||
| self.assertRaisesRegex( | ||
| ValueError, | ||
| r"Only can inner \(intersect\) or outer \(union\) join the other axis.", | ||
| lambda: ks.concat([kdf.A, kdf4.B], join="", axis=1), | ||
| ) | ||
|
|
||
| self.assertRaisesRegex( | ||
| ValueError, | ||
| r"Labels have to be unique; however, got duplicated labels \['A'\].", | ||
| lambda: ks.concat([kdf.A, kdf4.A], join="inner", axis=1), | ||
| ) | ||
|
Member
Author
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. This test also was added to verify duplicated column cases. |
||
|
|
||
| def test_concat_column_axis(self): | ||
| pdf1 = pd.DataFrame({"A": [0, 2, 4], "B": [1, 3, 5]}, index=[1, 2, 3]) | ||
| pdf2 = pd.DataFrame({"C": [1, 2, 3], "D": [4, 5, 6]}, index=[1, 3, 5]) | ||
| kdf1 = ks.from_pandas(pdf1) | ||
| kdf2 = ks.from_pandas(pdf2) | ||
|
|
||
| kdf3 = kdf1.copy() | ||
| kdf4 = kdf2.copy() | ||
| pdf3 = pdf1.copy() | ||
| pdf4 = pdf2.copy() | ||
|
|
||
| columns = pd.MultiIndex.from_tuples([("X", "A"), ("X", "B")]) | ||
| pdf3.columns = columns | ||
| kdf3.columns = columns | ||
|
|
||
| columns = pd.MultiIndex.from_tuples([("X", "C"), ("X", "D")]) | ||
| pdf4.columns = columns | ||
| kdf4.columns = columns | ||
|
|
||
| ignore_indexes = [True, False] | ||
| joins = ["inner", "outer"] | ||
|
|
||
| objs = [ | ||
| ([kdf1.A, kdf2.C], [pdf1.A, pdf2.C]), | ||
| ([kdf1, kdf2.C], [pdf1, pdf2.C]), | ||
| ([kdf1.A, kdf2], [pdf1.A, pdf2]), | ||
| ([kdf1.A, kdf2.C], [pdf1.A, pdf2.C]), | ||
| ([kdf1.A, kdf1.A.rename("B")], [pdf1.A, pdf1.A.rename("B")]), | ||
| ([kdf3[("X", "A")], kdf4[("X", "C")]], [pdf3[("X", "A")], pdf4[("X", "C")]]), | ||
| ([kdf3, kdf4[("X", "C")]], [pdf3, pdf4[("X", "C")]]), | ||
| ([kdf3[("X", "A")], kdf4], [pdf3[("X", "A")], pdf4]), | ||
| ([kdf3, kdf4], [pdf3, pdf4]), | ||
| ([kdf3[("X", "A")], kdf3[("X", "B")]], [pdf3[("X", "A")], pdf3[("X", "B")]],), | ||
| ( | ||
| [kdf3[("X", "A")], kdf3[("X", "B")].rename("ABC")], | ||
| [pdf3[("X", "A")], pdf3[("X", "B")].rename("ABC")], | ||
| ), | ||
| ( | ||
| [kdf3[("X", "A")].rename("ABC"), kdf3[("X", "B")]], | ||
| [pdf3[("X", "A")].rename("ABC"), pdf3[("X", "B")]], | ||
| ), | ||
|
Member
Author
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. This two test cases were added to verify single index vs multi-index in the column. |
||
| ] | ||
|
|
||
| for ignore_index, join in itertools.product(ignore_indexes, joins): | ||
| for obj in objs: | ||
| kdfs, pdfs = obj | ||
| with self.subTest(ignore_index=ignore_index, join=join, objs=obj): | ||
| actual = ks.concat(kdfs, axis=1, ignore_index=ignore_index, join=join) | ||
| expected = pd.concat(pdfs, axis=1, ignore_index=ignore_index, join=join) | ||
| self.assert_eq( | ||
| repr(actual.sort_values(list(actual.columns)).reset_index(drop=True)), | ||
| repr(expected.sort_values(list(expected.columns)).reset_index(drop=True)), | ||
| ) | ||
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.
Uh oh!
There was an error while loading. Please reload this page.