TypeError:类型别名不能与isinstance()一起使用

编程入门 行业动态 更新时间:2024-10-27 07:17:27
本文介绍了TypeError:类型别名不能与isinstance()一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

自从我将pandas升级到0.23.0以来,我在运行删除空白df.any_column = df.any_column.str.replace(' ','')

Ever since I upgraded pandas to 0.23.0, I'm getting this error for running a line to remove whitespace df.any_column = df.any_column.str.replace(' ','')

我收到的错误消息如下:

The error message that I'm getting is below:

/usr/local/lib/python3.5/dist-packages/pandas/core/strings.py in replace(self, pat, repl, n, case, flags, regex) 2427 def replace(self, pat, repl, n=-1, case=None, flags=0, regex=True): 2428 result = str_replace(self._data, pat, repl, n=n, case=case, -> 2429 flags=flags, regex=regex) 2430 return self._wrap_result(result) 2431 /usr/local/lib/python3.5/dist-packages/pandas/core/strings.py in str_replace(arr, pat, repl, n, case, flags, regex) 637 raise TypeError("repl must be a string or callable") 638 --> 639 is_compiled_re = is_re(pat) 640 if regex: 641 if is_compiled_re: /usr/local/lib/python3.5/dist-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().

我该如何解决?

推荐答案

这是Python 3.5.2及更低版本的错误.升级您的python(类似于3.5.4或更高版本),或者等到下一个pandas版本发布,其中包括以下修复程序: github/pandas-dev/pandas/pull/21098

That's a bug in Python 3.5.2 and lower. Either upgrade your python (something like 3.5.4 or newer should work), or wait till the next pandas release, which includes the fix: github/pandas-dev/pandas/pull/21098

更多推荐

TypeError:类型别名不能与isinstance()一起使用

本文发布于:2023-11-15 17:05:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1596340.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:别名   能与   类型   TypeError   isinstance

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!