pandas.algos._return_false causes picklingerror with dill.dump_session on centos

  • Last Update :
  • Techknowledgy :

I'm not seeing what you are seeing on a mac. Here's what I see, using the same version of pandas. I do see that you are using a different version of dill. I'm using the version from github. I'll check if there was a tweak to saving modules or globals in dill that might have had that impact on some distros.

Python 2.7.8 (default, Jul 13 2014, 02:29:54)
[GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.66))] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas
>>> import dill
>>> dill.detect.trace(True)
>>> dill.dump_session('x.pkl')
M1: <module '__main__' (built-in)>
   F2: <function _import_module at 0x1069ff140>
      D2: <dict object at 0x106a0b280>
         M2: <module 'dill' from '/Users/mmckerns/lib/python2.7/site-packages/dill-0.2.2.dev-py2.7.egg/dill/__init__.pyc'>
            M2: <module 'pandas' from '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/__init__.pyc'>

Here is what I get for pandas.algos,

Python 2.7 .8(
   default, Jul 13 2014, 02: 29: 54)[GCC 4.2 .1 Compatible Apple Clang 4.1((tags / Apple / clang - 421.11 .66))] on darwin
Type "help", "copyright", "credits"
or "license"
for more information. >>>
   import pandas.algos >>>
   import dill >>>
   dill.dumps(pandas.algos)
'\x80\x02cdill.dill\n_import_module\nq\x00U\x0cpandas.algosq\x01\x85q\x02Rq\x03.'

Here's what I get for pandas.algos._return_false:

Python 2.7.8 (default, Jul 13 2014, 02:29:54)
[GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.66))] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import dill
>>> import pandas.algos
>>> dill.dumps(pandas.algos._return_false)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
      File "/Users/mmckerns/lib/python2.7/site-packages/dill-0.2.2.dev-py2.7.egg/dill/dill.py", line 180, in dumps
      dump(obj, file, protocol, byref, file_mode, safeio)
      File "/Users/mmckerns/lib/python2.7/site-packages/dill-0.2.2.dev-py2.7.egg/dill/dill.py", line 173, in dump
      pik.dump(obj)
      File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 224, in dump
      self.save(obj)
      File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 317, in save
      self.save_global(obj, rv)
      File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 748, in save_global
      (obj, module, name))
      pickle.PicklingError: Can't pickle <cyfunction lambda1 at 0x10d403cc8>: it's not found as pandas.algos.lambda1

So apparently, I can pick up a lambda1 by trying to get the source of the object… which for lambda, if it can't get the source, dill will grab by name… and apparently it's named lambda1… even though that doesn't show up in the .pyx file. Maybe it's due to how cython builds the lambdas.

Python 2.7 .8(
   default, Jul 13 2014, 02: 29: 54)[GCC 4.2 .1 Compatible Apple Clang 4.1((tags / Apple / clang - 421.11 .66))] on darwin
Type "help", "copyright", "credits"
or "license"
for more information. >>>
   import pandas.algos >>>
   import dill >>>
   dill.source.importable(pandas.algos._return_false)
'from pandas import lambda1\n'

Suggestion : 2

This seems to be due to different handling of pandas.algos by the two OS-s (perhaps different compilers?). On my PC, where dump_session is without errors, pandas.algos._return_false is <cyfunction <lambda> at 0x06DD02A0>, while on CentOS it's <cyfunction lambda1 at 0x1df3050>. Why is it handled differently?, 4 days ago Being able to dump and restore a session is a key feature. One way of doing that with python is to use dump_session() in the dill package. In an … ,The problem seems to stem from pandas.algos. In fact, it's enough to run this to reproduce the error:, 5 days ago Pandas : pandas.algos._return_false causes PicklingError with dill.dump_session on CentOS [ Beautify Your Computer : https://www.hows.tech/p/recommended.html...


import pandas
import dill dill.dump_session('x.dat')
import pandas
import dill dill.dump_session('x.dat')
import pandas.algos
import dill dill.dump_session('x.dat') / dill.dumps(pandas.algos)
>>>dill.detect.badobjects(pandas.algos, depth = 1) {'__builtins__': <module '__builtin__' (built-in)>,  '_return_true': <cyfunction lambda2 at 0x1484d70>,  'np': <module 'numpy' from '/usr/local/lib/python2.7/site-packages/numpy-1.8.2-py2.7-linux-x86_64.egg/numpy/__init__.pyc'>,  '_return_false': <cyfunction lambda1 at 0x1484cc8>,  'lib': <module 'pandas.lib' from '/home/talkr/.local/lib/python2.7/site-packages/pandas/lib.so'>} 
Python 2.7.8 (default, Jul 13 2014, 02:29:54) [GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.66))] on darwin Type "help", "copyright", "credits" or "license" for more information. >>>import pandas >>>import dill >>>dill.detect.trace(True) >>>dill.dump_session('x.pkl') M1: <module '__main__' (built-in)>F2: <function _import_module at 0x1069ff140>D2: <dict object at 0x106a0b280>M2: <module 'dill' from '/Users/mmckerns/lib/python2.7/site-packages/dill-0.2.2.dev-py2.7.egg/dill/__init__.pyc'>M2: <module 'pandas' from '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/__init__.pyc'>
Python 2.7 .8(
   default, Jul 13 2014, 02: 29: 54)[GCC 4.2 .1 Compatible Apple Clang 4.1((tags / Apple / clang - 421.11 .66))] on darwin Type "help", "copyright", "credits"
or "license"
for more information. >>>
   import pandas.algos >>>
   import dill >>> dill.dumps(pandas.algos)
'\x80\x02cdill.dill\n_import_module\nq\x00U\x0cpandas.algosq\x01\x85q\x02Rq\x03.'

Suggestion : 3

pandas.algos._return_false在CentOS上导致带有dill.dump_session的PicklingError,这篇关于pandas.algos._return_false在CentOS上导致带有dill.dump_session的PicklingError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!,This seems to be due to different handling of pandas.algos by the two OS-s (perhaps different compilers?). On my PC, where dump_session is without errors, pandas.algos._return_false is <cyfunction <lambda> at 0x06DD02A0>, while on CentOS it's <cyfunction lambda1 at 0x1df3050>. Why is it handled differently?,I have a code framework which involves dumping sessions with dill. This used to work just fine, until I started to use pandas. The following code raises a PicklingError on CentOS release 6.5:

I have a code framework which involves dumping sessions with dill. This used to work just fine, until I started to use pandas. The following code raises a PicklingError on CentOS release 6.5:

import pandas
import dill
dill.dump_session('x.dat')

The problem seems to stem from pandas.algos. In fact, it's enough to run this to reproduce the error:

import pandas.algos
import dill
dill.dump_session('x.dat') / dill.dumps(pandas.algos)

看坏物体,我得到:

>>> dill.detect.badobjects(pandas.algos, depth = 1)
{'__builtins__': <module '__builtin__' (built-in)>, 
'_return_true': <cyfunction lambda2 at 0x1484d70>, 
'np': <module 'numpy' from '/usr/local/lib/python2.7/site-packages/numpy-1.8.2-py2.7-linux-x86_64.egg/numpy/__init__.pyc'>, 
'_return_false': <cyfunction lambda1 at 0x1484cc8>, 
'lib': <module 'pandas.lib' from '/home/talkr/.local/lib/python2.7/site-packages/pandas/lib.so'>}

这是我得到的pandas.algos

Python 2.7 .8(
   default, Jul 13 2014, 02: 29: 54)[GCC 4.2 .1 Compatible Apple Clang 4.1((tags / Apple / clang - 421.11 .66))] on darwin
Type "help", "copyright", "credits"
or "license"
for more information. >>>
   import pandas.algos >>>
   import dill >>>
   dill.dumps(pandas.algos)
'\x80\x02cdill.dill\n_import_module\nq\x00U\x0cpandas.algosq\x01\x85q\x02Rq\x03.'

这是pandas.algos._return_false我得到的:

Python 2.7.8 (default, Jul 13 2014, 02:29:54)
[GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.66))] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import dill
>>> import pandas.algos
>>> dill.dumps(pandas.algos._return_false)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
      File "/Users/mmckerns/lib/python2.7/site-packages/dill-0.2.2.dev-py2.7.egg/dill/dill.py", line 180, in dumps
      dump(obj, file, protocol, byref, file_mode, safeio)
      File "/Users/mmckerns/lib/python2.7/site-packages/dill-0.2.2.dev-py2.7.egg/dill/dill.py", line 173, in dump
      pik.dump(obj)
      File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 224, in dump
      self.save(obj)
      File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 317, in save
      self.save_global(obj, rv)
      File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 748, in save_global
      (obj, module, name))
      pickle.PicklingError: Can't pickle <cyfunction lambda1 at 0x10d403cc8>: it's not found as pandas.algos.lambda1

Suggestion : 4

Fastest way of searching matching string in two large dataframes using Pandas Python,Search for a partial string match in a data frame column from a list - Pandas - Python,count occurrences matching partial string by column in pandas python,searching matching string pattern from dataframe column in python pandas

Use the contains method (which even takes regular expresions). Something like this:

toUse = df['col1'].str.contains(Val)
valsIwant = df['col2'][toUse]

Suggestion : 5

У меня есть структура кода, которая включает в себя сеансы демпинга с укропом. Это работало нормально, пока я не начал использовать pandas. Следующий код вызывает выпуск PicklingError на CentOS 6.5:, 0 Но я получаю ту же ошибку на моем компьютере с dill.dumps(pandas.algos._return_false) : PicklingError: Can't pickle <cyfunction <lambda> at 0x06DD02A0>: it's not found as pandas.algos.lambda1 Korem 01 сен. 2014, в 21:57 ,Вот что я получаю за pandas.algos._return_false:,Кажется, это связано с различной обработкой pandas.algos двумя OS-s (возможно, разными компиляторами?). На моем ПК, где dump_session без ошибок, pandas.algos._return_false есть <cyfunction <lambda> at 0x06DD02A0>, а на CentOS - <cyfunction lambda1 at 0x1df3050>. Почему это происходит по-другому?

У меня есть структура кода, которая включает в себя сеансы демпинга с укропом. Это работало нормально, пока я не начал использовать pandas. Следующий код вызывает выпуск PicklingError на CentOS 6.5:

import pandas
import dill
dill.dump_session('x.dat')

Проблема, похоже, связана с pandas.algos. На самом деле, этого достаточно, чтобы запустить это, чтобы воспроизвести ошибку:

import pandas.algos
import dill
dill.dump_session('x.dat') / dill.dumps(pandas.algos)

Глядя на badobjects, я получаю:

>>> dill.detect.badobjects(pandas.algos, depth = 1)
{'__builtins__': <module '__builtin__' (built-in)>, 
'_return_true': <cyfunction lambda2 at 0x1484d70>, 
'np': <module 'numpy' from '/usr/local/lib/python2.7/site-packages/numpy-1.8.2-py2.7-linux-x86_64.egg/numpy/__init__.pyc'>, 
'_return_false': <cyfunction lambda1 at 0x1484cc8>, 
'lib': <module 'pandas.lib' from '/home/talkr/.local/lib/python2.7/site-packages/pandas/lib.so'>}

Я не вижу, что вы видите на Mac. Вот что я вижу, используя ту же версию pandas. Я вижу, что вы используете другую версию dill. Я использую версию из github. Я проверю, есть ли способ сохранить модули или глобальные переменные в dill, которые могли повлиять на некоторые дистрибутивы.

Python 2.7.8 (default, Jul 13 2014, 02:29:54)
[GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.66))] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas
>>> import dill
>>> dill.detect.trace(True)
>>> dill.dump_session('x.pkl')
M1: <module '__main__' (built-in)>
   F2: <function _import_module at 0x1069ff140>
      D2: <dict object at 0x106a0b280>
         M2: <module 'dill' from '/Users/mmckerns/lib/python2.7/site-packages/dill-0.2.2.dev-py2.7.egg/dill/__init__.pyc'>
            M2: <module 'pandas' from '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/__init__.pyc'>

Вот что я получаю за pandas.algos,

Python 2.7 .8(
   default, Jul 13 2014, 02: 29: 54)[GCC 4.2 .1 Compatible Apple Clang 4.1((tags / Apple / clang - 421.11 .66))] on darwin
Type "help", "copyright", "credits"
or "license"
for more information. >>>
   import pandas.algos >>>
   import dill >>>
   dill.dumps(pandas.algos)
'\x80\x02cdill.dill\n_import_module\nq\x00U\x0cpandas.algosq\x01\x85q\x02Rq\x03.'

Вот что я получаю за pandas.algos._return_false:

Python 2.7.8 (default, Jul 13 2014, 02:29:54)
[GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.66))] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import dill
>>> import pandas.algos
>>> dill.dumps(pandas.algos._return_false)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
      File "/Users/mmckerns/lib/python2.7/site-packages/dill-0.2.2.dev-py2.7.egg/dill/dill.py", line 180, in dumps
      dump(obj, file, protocol, byref, file_mode, safeio)
      File "/Users/mmckerns/lib/python2.7/site-packages/dill-0.2.2.dev-py2.7.egg/dill/dill.py", line 173, in dump
      pik.dump(obj)
      File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 224, in dump
      self.save(obj)
      File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 317, in save
      self.save_global(obj, rv)
      File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 748, in save_global
      (obj, module, name))
      pickle.PicklingError: Can't pickle <cyfunction lambda1 at 0x10d403cc8>: it not found as pandas.algos.lambda1

Итак, я могу подобрать lambda1, пытаясь получить источник объекта... который для лямбда, если он не может получить источник, dill будет захватывать по имени... и, по-видимому, он называется lambda1... хотя это не отображается в файле .pyx. Возможно, это связано с тем, как cython строит лямбды.

Python 2.7 .8(
   default, Jul 13 2014, 02: 29: 54)[GCC 4.2 .1 Compatible Apple Clang 4.1((tags / Apple / clang - 421.11 .66))] on darwin
Type "help", "copyright", "credits"
or "license"
for more information. >>>
   import pandas.algos >>>
   import dill >>>
   dill.source.importable(pandas.algos._return_false)
'from pandas import lambda1\n'

Suggestion : 6

问题似乎源于pandas.algos.实际上,运行它来重现错误就足够了:,我有一个代码框架,涉及使用dill转储会话.这曾经工作得很好,直到我开始使用熊猫.以下代码在CentOS 6.5版上引发了PicklingError:,错误是pickle.PicklingError: Can't pickle <cyfunction lambda1 at 0x1df3050>: it's not found as pandas.algos.lambda1.,这似乎是由于pandas.algos两个OS-s(可能是不同的编译器?)的不同处理.在我的电脑,在这里dump_session是没有错误的,pandas.algos._return_false是<cyfunction <lambda> at 0x06DD02A0>,虽然在CentOS它<cyfunction lambda1 at 0x1df3050>.为什么处理方式不同?

我有一个代码框架,涉及使用dill转储会话.这曾经工作得很好,直到我开始使用熊猫.以下代码在CentOS 6.5版上引发了PicklingError:

import pandas
import dill
dill.dump_session('x.dat')

问题似乎源于pandas.algos.实际上,运行它来重现错误就足够了:

import pandas.algos
import dill
dill.dump_session('x.dat') / dill.dumps(pandas.algos)

看一下badobjects,我得到:

>>> dill.detect.badobjects(pandas.algos, depth = 1)
{'__builtins__': <module '__builtin__' (built-in)>, 
'_return_true': <cyfunction lambda2 at 0x1484d70>, 
'np': <module 'numpy' from '/usr/local/lib/python2.7/site-packages/numpy-1.8.2-py2.7-linux-x86_64.egg/numpy/__init__.pyc'>, 
'_return_false': <cyfunction lambda1 at 0x1484cc8>, 
'lib': <module 'pandas.lib' from '/home/talkr/.local/lib/python2.7/site-packages/pandas/lib.so'>}

我没看到你在mac上看到的东西.这是我看到的,使用相同版本的pandas.我确实看到你使用的是另一个版本dill.我正在使用github的版本.我将检查是否存在对保存模块或全局变量的调整,dill这可能对某些发行版产生了影响.

Python 2.7.8 (default, Jul 13 2014, 02:29:54)
[GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.66))] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas
>>> import dill
>>> dill.detect.trace(True)
>>> dill.dump_session('x.pkl')
M1: <module '__main__' (built-in)>
   F2: <function _import_module at 0x1069ff140>
      D2: <dict object at 0x106a0b280>
         M2: <module 'dill' from '/Users/mmckerns/lib/python2.7/site-packages/dill-0.2.2.dev-py2.7.egg/dill/__init__.pyc'>
            M2: <module 'pandas' from '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/__init__.pyc'>

这是我得到的pandas.algos,

Python 2.7 .8(
   default, Jul 13 2014, 02: 29: 54)[GCC 4.2 .1 Compatible Apple Clang 4.1((tags / Apple / clang - 421.11 .66))] on darwin
Type "help", "copyright", "credits"
or "license"
for more information. >>>
   import pandas.algos >>>
   import dill >>>
   dill.dumps(pandas.algos)
'\x80\x02cdill.dill\n_import_module\nq\x00U\x0cpandas.algosq\x01\x85q\x02Rq\x03.'

这是我得到的pandas.algos._return_false:

Python 2.7.8 (default, Jul 13 2014, 02:29:54)
[GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.66))] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import dill
>>> import pandas.algos
>>> dill.dumps(pandas.algos._return_false)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
      File "/Users/mmckerns/lib/python2.7/site-packages/dill-0.2.2.dev-py2.7.egg/dill/dill.py", line 180, in dumps
      dump(obj, file, protocol, byref, file_mode, safeio)
      File "/Users/mmckerns/lib/python2.7/site-packages/dill-0.2.2.dev-py2.7.egg/dill/dill.py", line 173, in dump
      pik.dump(obj)
      File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 224, in dump
      self.save(obj)
      File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 317, in save
      self.save_global(obj, rv)
      File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 748, in save_global
      (obj, module, name))
      pickle.PicklingError: Can't pickle <cyfunction lambda1 at 0x10d403cc8>: it's not found as pandas.algos.lambda1

显然,我可以lambda1通过尝试获取对象的来源来获取a ...对于lambda,如果它无法获取源,dill将按名称获取...并且显然它被命名为lambda1......即使它没有出现在.pyx文件.也许这是由于如何cython构建lambdas.

Python 2.7 .8(
   default, Jul 13 2014, 02: 29: 54)[GCC 4.2 .1 Compatible Apple Clang 4.1((tags / Apple / clang - 421.11 .66))] on darwin
Type "help", "copyright", "credits"
or "license"
for more information. >>>
   import pandas.algos >>>
   import dill >>>
   dill.source.importable(pandas.algos._return_false)
'from pandas import lambda1\n'