Skip to content

replace function broken for Series with dtype: datetime64 #11868

Closed
@shanmuga-cv

Description

@shanmuga-cv

This bug was introduced in v0.17.1

from datetime import datetime
import pandas as pd
ser = pd.Series([datetime.now()]*4, index=range(4))
ser.replace('a', 10)

This throws the following exception.

Traceback (most recent call last):  
  File "/home/xxxx/anaconda/envs/py3/lib/python3.4/site-packages/pandas/core/internals.py", line 2061, in _try_coerce_args  
    other = other.astype('i8',copy=False).view('i8')  
ValueError: invalid literal for int() with base 10: 'a'  
  
During handling of the above exception, another exception occurred:  
  
Traceback (most recent call last):  
  File "/home/xxxx/anaconda/envs/py3/lib/python3.4/site-packages/pandas/core/internals.py", line 594, in replace  
    values, _, to_replace, _ = self._try_coerce_args(self.values, to_replace)  
  File "/home/xxxx/anaconda/envs/py3/lib/python3.4/site-packages/pandas/core/internals.py", line 2066, in _try_coerce_args  
    raise TypeError  
TypeError  
  
During handling of the above exception, another exception occurred:  
  
Traceback (most recent call last):  
  File "", line 1, in   
  File "/home/xxxx/anaconda/envs/py3/lib/python3.4/site-packages/pandas/core/generic.py", line 3110, in replace  
    inplace=inplace, regex=regex)  
  File "/home/xxxx/anaconda/envs/py3/lib/python3.4/site-packages/pandas/core/internals.py", line 2870, in replace  
    return self.apply('replace', **kwargs)  
  File "/home/xxxx/anaconda/envs/py3/lib/python3.4/site-packages/pandas/core/internals.py", line 2823, in apply  
    applied = getattr(b, f)(**kwargs)  
  File "/home/xxxx/anaconda/envs/py3/lib/python3.4/site-packages/pandas/core/internals.py", line 607, in replace  
    if not mask.any():  
UnboundLocalError: local variable 'mask' referenced before assignment  

Metadata

Metadata

Assignees

No one assigned

    Labels

    DatetimeDatetime data dtypeDuplicate ReportDuplicate issue or pull requestMissing-datanp.nan, pd.NaT, pd.NA, dropna, isnull, interpolate

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions