Python:在源代码中初始化类会导致NameError

时间:2018-04-24 06:23:03

标签: python nameerror

我是一个仍在学习绳索的蟒蛇noobie

初始化GroupBy(_GroupBy)导致我的代码给出了一个 NameError:name' _get_grouper'未定义

OLE DB provider "SQLNCLI11" for linked server "AWSMSSQL" returned message "The partner transaction manager has disabled its support for remote/network transactions.".
Msg 7391, Level 16, State 2, Procedure ms_item, Line 29
The operation could not be performed because OLE DB provider "SQLNCLI11" for linked server "AWSMSSQL" was unable to begin a distributed transaction.

_get_grouper在_GroupBy

的init中调用
class GroupBy(_GroupBy):
    def _add_numeric_operations(cls):        
        cls.first = GroupBy(_GroupBy).nth(-1, dropna=False)
class _GroupBy(PandasObject, SelectionMixin):
    def __init__(self, obj, keys=None, axis=0, level=None,
        grouper=None, exclusions=None, selection=None, as_index=True,
        sort=True, group_keys=True, squeeze=False, **kwargs):
        if grouper is None:

            grouper, exclusions, obj = _get_grouper(obj, keys,
                                                    axis=axis,
                                                    level=level,
                                                    sort=sort,
                                                  mutated=self.mutated)

如果我在python命令行中调用它,第n个方法会起作用,但是在源代码中初始化它的类会引发此错误。我错过了什么?

1 个答案:

答案 0 :(得分:0)

您已在_get_grouper()__init__中调用了_GroupBy

首先,您最好删除该递归调用。 通常,您可以创建另一个实现来替换递归调用

在班级__init__的{​​{1}}中,将_GroupBy替换为_get_grouper(),以澄清哪个班级有Grouper._get_grouper()

这些可以解决问题。