Skip to content
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

Fix Frame.abs to support bool type and disallow non-numeric types. #1980

Merged
merged 2 commits into from
Dec 23, 2020

Conversation

ueshin
Copy link
Collaborator

@ueshin ueshin commented Dec 22, 2020

Fixes Frame.abs to support bool type and disallow non-numeric types.

@ueshin ueshin requested a review from xinrong-meng December 22, 2020 22:21
}
)
kdf = ks.from_pandas(pdf)
self.assert_eq(kdf.A.abs(), pdf.A.abs())
self.assert_eq(kdf.B.abs(), pdf.B.abs())
self.assert_eq(kdf.E.abs(), pdf.E.abs())
# pandas' bug?
# self.assert_eq(kdf[["B", "C", "E"]].abs(), pdf[["B", "C", "E"]].abs())
Copy link
Collaborator Author

@ueshin ueshin Dec 22, 2020

Choose a reason for hiding this comment

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

The pandas result is:

>>> pdf = pd.DataFrame(
...     {
...         "A": [1, -2, 3, -4, 5],
...         "B": [1.0, -2, 3, -4, 5],
...         "C": [-6.0, -7, -8, -9, 10],
...         "D": ["a", "b", "c", "d", "e"],
...         "E": [True, False, False, True, True],
...     }
... )
>>> pdf[["B", "C", "E"]].abs()
   B   C  E
0  1   6  1
1  2   7  0
2  3   8  0
3  4   9  1
4  5  10  1

whereas calculating separately:

>>> pdf[["B", "C"]].abs()
     B     C
0  1.0   6.0
1  2.0   7.0
2  3.0   8.0
3  4.0   9.0
4  5.0  10.0
>>> pdf[["E"]].abs()
       E
0   True
1  False
2  False
3   True
4   True

I believe this is a pandas bug.

The current Koalas behavior:

>>> ks.from_pandas(pdf)[["B", "C", "E"]].abs()
     B     C      E
0  1.0   6.0   True
1  2.0   7.0  False
2  3.0   8.0  False
3  4.0   9.0   True
4  5.0  10.0   True

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems pandas bug to me, too. Let me report this to pandas dev.

@codecov-io
Copy link

codecov-io commented Dec 22, 2020

Codecov Report

Merging #1980 (87d0a2c) into master (dd9661f) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1980   +/-   ##
=======================================
  Coverage   94.57%   94.57%           
=======================================
  Files          50       50           
  Lines       10946    10952    +6     
=======================================
+ Hits        10352    10358    +6     
  Misses        594      594           
Impacted Files Coverage Δ
databricks/koalas/generic.py 92.26% <100.00%> (+0.11%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dd9661f...87d0a2c. Read the comment docs.

return kser.spark.transform(F.abs)
else:
raise TypeError(
"bad operand type for abs(): {}".format(kser.spark.data_type.simpleString())
Copy link
Member

@HyukjinKwon HyukjinKwon Dec 23, 2020

Choose a reason for hiding this comment

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

Hm, should we show pandas' dtype instead of Spark data type?

Copy link
Collaborator Author

@ueshin ueshin Dec 23, 2020

Choose a reason for hiding this comment

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

In that case, shall we address it separately. The same error message will appear in the other places.

Copy link
Member

@HyukjinKwon HyukjinKwon left a comment

Choose a reason for hiding this comment

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

LGTM otherwise

Copy link
Contributor

@itholic itholic left a comment

Choose a reason for hiding this comment

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

LGTM. Let's address #1980 (comment) in separately.

@ueshin
Copy link
Collaborator Author

ueshin commented Dec 23, 2020

Thanks! merging.

@ueshin ueshin merged commit 4c86f3c into databricks:master Dec 23, 2020
@ueshin ueshin deleted the abc branch December 23, 2020 18:09
HyukjinKwon pushed a commit that referenced this pull request Dec 26, 2020
rising-star92 added a commit to rising-star92/databricks-koalas that referenced this pull request Jan 27, 2023
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.

4 participants