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/API: Fix .replace dtype conversion rules #12747

Closed
sinhrks opened this issue Mar 30, 2016 · 4 comments · Fixed by #15742
Closed

BUG/API: Fix .replace dtype conversion rules #12747

sinhrks opened this issue Mar 30, 2016 · 4 comments · Fixed by #15742

Comments

@sinhrks
Copy link
Member

sinhrks commented Mar 30, 2016

Code Sample, a copy-pastable example if possible

1. replace bool with int (#12780)

NG, should be int Series

pd.Series([True]).replace({True: 3})
#0    True
# dtype: bool
2. replace datetime/timedelta with int (#12780)

NG, should be int Series

pd.Series([pd.Timestamp('2011-01-01')]).replace({pd.Timestamp('2011-01-01'): 3})
#0   1970-01-01 00:00:00.000000003
# dtype: datetime64[ns]

pd.Series([pd.Timedelta('1 days')]).replace({pd.Timedelta('1 days'): 3})
#0   00:00:00.000000
# dtype: timedelta64[ns]
3. replace datetime/timedelta with object (#12780)

NG, coerced to internal repr unexpectedly.

rep = {pd.Timestamp('2011-01-01'): 'a', pd.Timestamp('2011-01-02'): 'b'}
pd.Series([pd.Timestamp('2011-01-01'), pd.Timestamp('2011-01-02')]).replace(rep)
#0    1293840000000000000
#1                      b
# dtype: object
4. replace with datetimetz (#12780)

NG, coerced to GMT

pd.Series(['a']).replace({'a': pd.Timestamp('2011-01-01', tz='US/Eastern')})
#0   2011-01-01 05:00:00
# dtype: datetime64[ns]
5. replacement of string (open, see #15743)
In [37]: pd.Series([1,2,3]).replace('1', np.nan)
Out[37]: 
0    NaN
1    2.0
2    3.0
dtype: float64

output of pd.show_versions()

Latest master.

@sinhrks sinhrks added this to the 0.18.1 milestone Mar 30, 2016
@jreback
Copy link
Contributor

jreback commented Mar 30, 2016

xref (and may close)
#9113

@jreback
Copy link
Contributor

jreback commented Mar 30, 2016

btw, the problem with the datetime with tz is that I force convert=False always (in the block). i don't remember exactly why I did this.

jreback pushed a commit that referenced this issue Apr 10, 2016
related to #12747 and #12780

Author: sinhrks <[email protected]>

Closes #12841 from sinhrks/dtype_tests and squashes the following commits:

e11cc2a [sinhrks] TST: Add numeric coercion tests
@jreback jreback modified the milestones: 0.18.2, 0.18.1 Apr 26, 2016
@jreback
Copy link
Contributor

jreback commented Apr 30, 2016

xref #13047

on 32-bit platform some conversions are messed up.

@jorisvandenbossche
Copy link
Member

jorisvandenbossche commented Nov 1, 2016

Additional case from #14550:

In [37]: pd.Series([1,2,3]).replace('1', np.nan)
Out[37]: 
0    NaN
1    2.0
2    3.0
dtype: float64

although here it is about coercing of the 'to_replace' value, and not of the fill value.

jreback pushed a commit to jreback/pandas that referenced this issue Mar 20, 2017
@jreback jreback modified the milestones: 0.20.0, Next Major Release Mar 20, 2017
jreback pushed a commit to jreback/pandas that referenced this issue Mar 20, 2017
closes pandas-dev#12747

Author: sinhrks <[email protected]>

This patch had conflicts when merged, resolved by
Committer: Jeff Reback <[email protected]>

Closes pandas-dev#12780 from sinhrks/replace_type and squashes the following commits:

f9154e8 [sinhrks] remove unnecessary comments
279fdf6 [sinhrks] remove import failure
de44877 [sinhrks] BUG: replace coerces incorrect dtype
AnkurDedania pushed a commit to AnkurDedania/pandas that referenced this issue Mar 21, 2017
closes pandas-dev#12747

Author: sinhrks <[email protected]>

This patch had conflicts when merged, resolved by
Committer: Jeff Reback <[email protected]>

Closes pandas-dev#12780 from sinhrks/replace_type and squashes the following commits:

f9154e8 [sinhrks] remove unnecessary comments
279fdf6 [sinhrks] remove import failure
de44877 [sinhrks] BUG: replace coerces incorrect dtype
mattip pushed a commit to mattip/pandas that referenced this issue Apr 3, 2017
closes pandas-dev#12747

Author: sinhrks <[email protected]>

This patch had conflicts when merged, resolved by
Committer: Jeff Reback <[email protected]>

Closes pandas-dev#12780 from sinhrks/replace_type and squashes the following commits:

f9154e8 [sinhrks] remove unnecessary comments
279fdf6 [sinhrks] remove import failure
de44877 [sinhrks] BUG: replace coerces incorrect dtype
jreback added a commit to jreback/pandas that referenced this issue May 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants