Skip to content

Version 0.23.0 bug in replace()? #21159

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

Closed
araichev opened this issue May 21, 2018 · 1 comment
Closed

Version 0.23.0 bug in replace()? #21159

araichev opened this issue May 21, 2018 · 1 comment
Labels
Compat pandas objects compatability with Numpy or Python functions
Milestone

Comments

@araichev
Copy link

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
@araichev araichev changed the title Regression bug in replace()? Regression bug in replace()? May 21, 2018
@araichev araichev changed the title Regression bug in replace()? New bug in replace()? May 21, 2018
@araichev araichev changed the title New bug in replace()? Version 0.23.0 bug in replace()? May 21, 2018
@jreback
Copy link
Contributor

jreback commented May 22, 2018

duplicate of #21078 and fixed in #21098

@jreback jreback closed this as completed May 22, 2018
@jreback jreback added the Compat pandas objects compatability with Numpy or Python functions label May 22, 2018
@jreback jreback added this to the 0.23.1 milestone May 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Compat pandas objects compatability with Numpy or Python functions
Projects
None yet
Development

No branches or pull requests

2 participants