Skip to content

Version 0.23.0 bug in replace()? #21159

Closed
@araichev

Description

@araichev

Hi folks,

In Pandas 0.23.0 (on Linux Mint 18.3), i run

import pandas as pd
import numpy as np


s = pd.Series([np.nan, 1])
s.fillna(-1).astype(int).astype(str).replace('-1', '')

and get the error

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-39-6bd382c335e3> in <module>()
      1 print(pd.__version__)
      2 s = pd.Series([np.nan, 1])
----> 3 s.fillna(-1).astype(int).astype(str).replace('-1', '')

~/.virtualenvs/make_gtfs-2RAnZ_bf/lib/python3.5/site-packages/pandas/core/series.py in replace(self, to_replace, value, inplace, limit, regex, method)
   3427         return super(Series, self).replace(to_replace=to_replace, value=value,
   3428                                            inplace=inplace, limit=limit,
-> 3429                                            regex=regex, method=method)
   3430 
   3431     @Appender(generic._shared_docs['shift'] % _shared_doc_kwargs)

~/.virtualenvs/make_gtfs-2RAnZ_bf/lib/python3.5/site-packages/pandas/core/generic.py in replace(self, to_replace, value, inplace, limit, regex, method)
   5877                     new_data = self._data.replace(to_replace=to_replace,
   5878                                                   value=value, inplace=inplace,
-> 5879                                                   regex=regex)
   5880                 else:
   5881                     msg = ('Invalid "to_replace" type: '

~/.virtualenvs/make_gtfs-2RAnZ_bf/lib/python3.5/site-packages/pandas/core/internals.py in replace(self, **kwargs)
   3718 
   3719     def replace(self, **kwargs):
-> 3720         return self.apply('replace', **kwargs)
   3721 
   3722     def replace_list(self, src_list, dest_list, inplace=False, regex=False,

~/.virtualenvs/make_gtfs-2RAnZ_bf/lib/python3.5/site-packages/pandas/core/internals.py in apply(self, f, axes, filter, do_integrity_check, consolidate, **kwargs)
   3579 
   3580             kwargs['mgr'] = self
-> 3581             applied = getattr(b, f)(**kwargs)
   3582             result_blocks = _extend_blocks(applied, result_blocks)
   3583 

~/.virtualenvs/make_gtfs-2RAnZ_bf/lib/python3.5/site-packages/pandas/core/internals.py in replace(self, to_replace, value, inplace, filter, regex, convert, mgr)
   2430         blocks = [self]
   2431 
-> 2432         if not either_list and is_re(to_replace):
   2433             return self._replace_single(to_replace, value, inplace=inplace,
   2434                                         filter=filter, regex=True,

~/.virtualenvs/make_gtfs-2RAnZ_bf/lib/python3.5/site-packages/pandas/core/dtypes/inference.py in is_re(obj)
    217     """
    218 
--> 219     return isinstance(obj, re_type)
    220 
    221 

/usr/lib/python3.5/typing.py in __instancecheck__(self, obj)
    258 
    259     def __instancecheck__(self, obj):
--> 260         raise TypeError("Type aliases cannot be used with isinstance().")
    261 
    262     def __subclasscheck__(self, cls):

TypeError: Type aliases cannot be used with isinstance().

I expect to get what i got using Pandas 0.22.0, namely

0     
1    1
dtype: object

Metadata

Metadata

Assignees

No one assigned

    Labels

    Compatpandas objects compatability with Numpy or Python functions

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions