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

Bug : Fixes #20911 #24467

Merged
merged 7 commits into from
Dec 28, 2018
Merged

Bug : Fixes #20911 #24467

merged 7 commits into from
Dec 28, 2018

Conversation

cgangwar11
Copy link
Contributor

@cgangwar11 cgangwar11 commented Dec 28, 2018

Before

In [1]: import pandas as pd                                                                   

In [2]: df1 = pd.DataFrame([[1., 0.], [3., 0.]], columns=['A', 'B']) 
   ...:                                                                                       

In [3]: df2 = pd.DataFrame([[100., 1.], [100., 2.]], columns=['B', 'A']) 
   ...:                                                                                       

In [4]: df1                                                                                   
Out[4]: 
     A    B
0  1.0  0.0
1  3.0  0.0

In [5]: df2                                                                                   
Out[5]: 
       B    A
0  100.0  1.0
1  100.0  2.0

In [6]: df1.clip(lower=0,upper=df2)                                                           
Out[6]: 
       A    B
0    1.0  0.0
1  100.0  0.0

After

In [5]: df1.clip(lower=0,upper=df2)                                                           
Out[5]: 
     A    B
0  1.0  0.0
1  2.0  0.0

Passing threshold as it is instead of numpy array to preserve the columns order.
Additional test cases to validate the fix
@pep8speaks
Copy link

pep8speaks commented Dec 28, 2018

Hello @cgangwar11! Thanks for updating the PR.

Cheers ! There are no PEP8 issues in this Pull Request. 🍻

Comment last updated on December 28, 2018 at 22:56 Hours UTC

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

pls add a whatsnew note

@@ -1964,6 +1964,13 @@ def test_clip_against_frame(self, axis):
tm.assert_frame_equal(clipped_df[lb_mask], lb[lb_mask])
tm.assert_frame_equal(clipped_df[ub_mask], ub[ub_mask])
tm.assert_frame_equal(clipped_df[mask], df[mask])
# GH 20911, clipping now preserves types
Copy link
Contributor

Choose a reason for hiding this comment

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

make this a new test

@@ -1964,6 +1964,13 @@ def test_clip_against_frame(self, axis):
tm.assert_frame_equal(clipped_df[lb_mask], lb[lb_mask])
tm.assert_frame_equal(clipped_df[ub_mask], ub[ub_mask])
tm.assert_frame_equal(clipped_df[mask], df[mask])
# GH 20911, clipping now preserves types
df1 = DataFrame(np.random.randn(1000,4), columns=['A', 'B','C','D'])
df2 = DataFrame(np.random.randn(1000,4), columns=['D', 'A','B','C'])
Copy link
Contributor

Choose a reason for hiding this comment

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

you have some lint errors.

df1 = DataFrame(np.random.randn(1000,4), columns=['A', 'B','C','D'])
df2 = DataFrame(np.random.randn(1000,4), columns=['D', 'A','B','C'])

res1 = df1.clip(lower=0,upper=df2)
Copy link
Contributor

Choose a reason for hiding this comment

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

use result= and expected=

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will do pardon me for such a rookie mistake....

@jreback jreback added Bug Numeric Operations Arithmetic, Comparison, and Logical operations labels Dec 28, 2018
@cgangwar11 cgangwar11 changed the title Local/20911 Bug : Fixes #20911 Dec 28, 2018
@codecov
Copy link

codecov bot commented Dec 28, 2018

Codecov Report

Merging #24467 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #24467   +/-   ##
=======================================
  Coverage    92.3%    92.3%           
=======================================
  Files         163      163           
  Lines       51969    51969           
=======================================
  Hits        47968    47968           
  Misses       4001     4001
Flag Coverage Δ
#multiple 90.7% <100%> (ø) ⬆️
#single 43.01% <0%> (ø) ⬆️
Impacted Files Coverage Δ
pandas/core/generic.py 96.62% <100%> (ø) ⬆️

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 aa1549f...3dabccf. Read the comment docs.

@codecov
Copy link

codecov bot commented Dec 28, 2018

Codecov Report

Merging #24467 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #24467      +/-   ##
==========================================
- Coverage   92.31%   92.31%   -0.01%     
==========================================
  Files         165      165              
  Lines       52252    52204      -48     
==========================================
- Hits        48237    48192      -45     
+ Misses       4015     4012       -3
Flag Coverage Δ
#multiple 90.73% <100%> (-0.01%) ⬇️
#single 42.96% <0%> (+0.01%) ⬆️
Impacted Files Coverage Δ
pandas/core/generic.py 96.62% <100%> (ø) ⬆️
pandas/core/arrays/timedeltas.py 87.36% <0%> (-0.27%) ⬇️
pandas/util/testing.py 87.75% <0%> (-0.1%) ⬇️
pandas/core/arrays/period.py 98.42% <0%> (-0.05%) ⬇️
pandas/core/indexes/datetimelike.py 97.53% <0%> (ø) ⬆️
pandas/core/arrays/base.py 98.23% <0%> (+0.03%) ⬆️
pandas/core/arrays/sparse.py 92.17% <0%> (+0.06%) ⬆️
pandas/core/arrays/datetimes.py 98.39% <0%> (+0.13%) ⬆️
pandas/core/arrays/datetimelike.py 96.08% <0%> (+0.43%) ⬆️

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 c1af4f5...9ee4b89. Read the comment docs.

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

pls add a whatsnew entry

# GH 20911
df1 = DataFrame(np.random.randn(1000, 4), columns=['A', 'B', 'C', 'D'])
df2 = DataFrame(np.random.randn(1000, 4), columns=['D', 'A', 'B', 'C'])
result = df1.clip(lower=0, upper=df2)
Copy link
Contributor

Choose a reason for hiding this comment

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

can you try this with lower as well

@jreback jreback added this to the 0.24.0 milestone Dec 28, 2018
@jreback
Copy link
Contributor

jreback commented Dec 28, 2018

lgtm ping on green

@cgangwar11
Copy link
Contributor Author

Better Example

Before`

In [11]: import pandas as pd
    ...: 
    ...: df1 = pd.DataFrame([[50., 60.,70.], [80., 90.,100.]], columns=['A', 'B','C'])
    ...: 
    ...: upper = pd.DataFrame([[50., 80.,49.], [100.,100.,90.]], columns=['B', 'C','A'])
    ...: 
    ...: lower = pd.DataFrame([[60., 40.,35.], [90.,95.,85.]], columns=['C', 'B','A'])
    ...: 
    ...: 

In [12]: df1
Out[12]: 
      A     B      C
0  50.0  60.0   70.0
1  80.0  90.0  100.0

In [16]: lower[df1.columns]
Out[16]: 
      A     B     C
0  35.0  40.0  60.0
1  85.0  95.0  90.0

In [17]: upper[df1.columns]
Out[17]: 
      A      B      C
0  49.0   50.0   80.0
1  90.0  100.0  100.0

In [18]: df1.clip(lower=lower,upper=upper)
Out[18]: 
      A     B      C
0  50.0  80.0   70.0
1  90.0  95.0  100.0

After

In [8]: (df1.clip(lower=lower, upper=upper))
Out[8]:
      A     B      C
0  49.0  50.0   70.0
1  85.0  95.0  100.0

@cgangwar11
Copy link
Contributor Author

@jreback it's green now

@jreback jreback merged commit 4f1c1dc into pandas-dev:master Dec 28, 2018
@jreback
Copy link
Contributor

jreback commented Dec 28, 2018

thanks @cgangwar11

@cgangwar11 cgangwar11 deleted the local/20911 branch January 3, 2019 18:16
Pingviinituutti pushed a commit to Pingviinituutti/pandas that referenced this pull request Feb 28, 2019
Pingviinituutti pushed a commit to Pingviinituutti/pandas that referenced this pull request Feb 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Numeric Operations Arithmetic, Comparison, and Logical operations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DataFrame.clip() bug when bound a frame when columns not sorted
3 participants