RuntimeError: uninitialized static method object

User 2594 | 12/6/2015, 12:52:58 AM

I'm taking the Coursera Machine Learning specialization, and I'm experimenting on the "analyzing product sentiment" dataset...

The error I'm getting is: `


RuntimeError Traceback (most recent call last) /Users/jarrowwx/.graphlab/anaconda/lib/python2.7/site-packages/IPython/core/formatters.pyc in call(self, obj) 688 typepprinters=self.typeprinters, 689 deferredpprinters=self.deferredprinters) --> 690 printer.pretty(obj) 691 printer.flush() 692 return stream.getvalue()

/Users/jarrowwx/.graphlab/anaconda/lib/python2.7/site-packages/IPython/lib/pretty.pyc in pretty(self, obj) 407 if callable(meth): 408 return meth(obj, self, cycle) --> 409 return defaultpprint(obj, self, cycle) 410 finally: 411 self.end_group()

/Users/jarrowwx/.graphlab/anaconda/lib/python2.7/site-packages/IPython/lib/pretty.pyc in defaultpprint(obj, p, cycle) 527 if safegetattr(klass, 'repr', None) not in baseclassreprs: 528 # A user-provided repr. Find newlines and replace them with p.break() --> 529 reprpprint(obj, p, cycle) 530 return 531 p.begingroup(1, '<')

/Users/jarrowwx/.graphlab/anaconda/lib/python2.7/site-packages/IPython/lib/pretty.pyc in reprpprint(obj, p, cycle) 709 """A pprint that just redirects to the normal repr function.""" 710 # Find newlines and replace them with p.break() --> 711 output = repr(obj) 712 for idx,outputline in enumerate(output.splitlines()): 713 if idx:

/Users/jarrowwx/.graphlab/anaconda/lib/python2.7/site-packages/graphlab/datastructures/sarray.pyc in repr(self) 619 Returns a string description of the SArray. 620 """ --> 621 datastr = self.str() 622 ret = "dtype: " + str(self.dtype().name) + "\n" 623 if (self.proxy.has_size()):

/Users/jarrowwx/.graphlab/anaconda/lib/python2.7/site-packages/graphlab/datastructures/sarray.pyc in str(self) 637 headln = str(list(self.astype(str).head(100))) 638 else: --> 639 headln = self.escapespace(str(list(self.head(100)))) 640 headln = unicode(headln.decode('stringescape'),'utf-8',errors='replace').encode('utf-8') 641 if (self.proxy.has_size() == False or self.size() > 100):

/Users/jarrowwx/.graphlab/anaconda/lib/python2.7/site-packages/graphlab/datastructures/sarray.pyc in head(self, n) 1131 [0, 1, 2, 3, 4] 1132 """ -> 1133 return SArray(proxy=self.proxy.head(n)) 1134 1135 def vector_slice(self, start, end=None):

graphlab/cython/cysarray.pyx in graphlab.cython.cysarray.UnitySArrayProxy.head()

graphlab/cython/cysarray.pyx in graphlab.cython.cysarray.UnitySArrayProxy.head()

RuntimeError: Runtime Exception. Traceback (most recent call last): File "<ipython-input-10-c056e8ff17bf>", line 17, in fn RuntimeError: uninitialized staticmethod object `

I'm getting this while trying to .apply(). Something about my function that I pass in is causing this. A simple function doesn't create the error. And it errors even if I'm only operating on the first three reviews. A form of this feature extraction function used to work. I am not sure what changed exactly that caused it. The only things that have changed that might be relevant is the introduction of import numpy (which it can't be, because I tried backing that part back out) and the creation of a few classes to make the feature selection process easier to comprehend and reason about. That change is too big to back out. So I'm kinda stuck.

While I continue to bang my head against this, does anyone have any ideas?

Comments

User 2594 | 12/6/2015, 1:10:10 AM

My feature extraction function looks like this: ` # in the context of my FeatureSet class def featureExtractor( self, windowsize = 7 ): def fn( originaltokens ):

        features = {}
        def feature( x ):
            if self.contains( x ) and not self.get( x ).ignore:
                features[x] = 1 + ( features[x] if ( x in features ) else 0 )

        tokens = [ token.lower() for token in original_tokens ] 
        last = len(tokens) - 1

        for i in range( 0, last + 1 ):
            a = tokens[i]
            feature( a )

            if i < last:
                feature( FeatureSet.getSequenceName( a, tokens[i+1] ) )

            limit = i + window_size - 1
            limit = last if limit > last else limit
            for j in range( i + 2, limit ):
                feature( FeatureSet.getPairName( a, tokens[j] ) )

        return features

    return fn    

I use it kinda like this: reviews['features'] = reviews['tokens'].apply( features.featureExtractor() ) ` When I call it on the list of tokens from one review, it returns the expected value, so it's not that.


User 2594 | 12/6/2015, 1:12:20 AM

ARGH! Found it...

The call FeatureSet.getSequenceName() - it is a static method, because it doesn't actually depend on the instance. But because the error was "uninitialized staticmethod object" I decided to try making them instance methods, and the problem went away.

Is this a bug, or a quirk?


User 15 | 12/8/2015, 11:41:40 PM

From what I can tell, it's a quirk...maybe a bug. We use the cloudpickle package to serialize python code to use in apply, and I think this is a cloudpickle issue. Good to know you were able to work around it though.