Skip to content

BUG: allow tuples in recursive call to replace #5145

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 1 commit into from
Oct 8, 2013
Merged

BUG: allow tuples in recursive call to replace #5145

merged 1 commit into from
Oct 8, 2013

Conversation

cpcloud
Copy link
Member

@cpcloud cpcloud commented Oct 7, 2013

This avoids the seeming passage of regular expressions

closes #5143.

@ghost ghost assigned cpcloud Oct 7, 2013
@cpcloud
Copy link
Member Author

cpcloud commented Oct 7, 2013

also fixes a bug where a Series wasn't accepted because it has no items method

@cpcloud
Copy link
Member Author

cpcloud commented Oct 8, 2013

the beast that is NDFrame.replace() could use a makeover ... will do it 0.14

@jreback
Copy link
Contributor

jreback commented Oct 8, 2013

here's a similar bug, I think:

comes up in test_replace_with_none_value

shows up on sparc/2.6, because the dictionary ordering is different (not sure why)

In [1]: df = DataFrame(dict(A = [np.nan,1]))

In [2]: df.replace(to_replace={nan: 0, 1: -1e8})
Out[2]: 
           A
0          0
1 -100000000

In [3]: df.replace(to_replace=(1,nan),value=(-1e8,0))
Out[3]: 
           A
0 -100000000
1          0

@jreback
Copy link
Contributor

jreback commented Oct 8, 2013

I don' think you can do it with a single masking in core/internals/Block/replace. I think that you have to iteratore over the to_replace/values and replace one-by-one

@cpcloud
Copy link
Member Author

cpcloud commented Oct 8, 2013

it does iterate one by one in ObjectBlock.replace()

@jreback
Copy link
Contributor

jreback commented Oct 8, 2013

ahh...but this is a FloatBlock, so doesn't!

@cpcloud
Copy link
Member Author

cpcloud commented Oct 8, 2013

oh fail ... ok ... it's becaue they are tuples

@jreback
Copy link
Contributor

jreback commented Oct 8, 2013

I was just simulating what your keys, values = zip(*items) does

@cpcloud
Copy link
Member Author

cpcloud commented Oct 8, 2013

right .... that's the bug

@jreback
Copy link
Contributor

jreback commented Oct 8, 2013

ahh...so this PR already fixes, then?

maybe add this add a test in that same routine?

        result = self.tsframe.replace(to_replace={nan: 0, 1: -1e8})
        result2 = self.tsframe.replace(to_replace=(1,nan),value=(-1e8,0))
        assert_frame_equal(result,result2)
.....

@cpcloud
Copy link
Member Author

cpcloud commented Oct 8, 2013

stop reading my mind!!!

@cpcloud
Copy link
Member Author

cpcloud commented Oct 8, 2013

😄

@jreback
Copy link
Contributor

jreback commented Oct 8, 2013

its odd...ONLY came up on 2.6 on sparc (the dict iterates in a different order)....

once you merge this...I can retest on sparc and close that other issue

@cpcloud
Copy link
Member Author

cpcloud commented Oct 8, 2013

soon as this passes....good to merge ...

@jreback @jtratner ?

@jreback
Copy link
Contributor

jreback commented Oct 8, 2013

looks fine to me

This fixes a bug that makes it appear as if replace is incorrectly using
regular expressions.
cpcloud added a commit that referenced this pull request Oct 8, 2013
BUG: allow tuples in recursive call to replace
@cpcloud cpcloud merged commit c9d004f into pandas-dev:master Oct 8, 2013
@cpcloud cpcloud deleted the replace-exact-fix branch October 8, 2013 04:35
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.

Replace partial matches behavior
2 participants