@@ -1890,18 +1890,14 @@ def rindex(self, sub, start=0, end=None):
18901890 docstring = _shared_docs ['ismethods' ] %
18911891 _shared_docs ['isdecimal' ])
18921892
1893-
1894- class StringAccessorMixin (object ):
1895- """ Mixin to add a `.str` acessor to the class."""
1896-
1897- # string methods
1898- def _make_str_accessor (self ):
1893+ @classmethod
1894+ def _make_accessor (cls , data ):
18991895 from pandas .core .index import Index
19001896
1901- if (isinstance (self , ABCSeries ) and
1902- not ((is_categorical_dtype (self .dtype ) and
1903- is_object_dtype (self .values .categories )) or
1904- (is_object_dtype (self .dtype )))):
1897+ if (isinstance (data , ABCSeries ) and
1898+ not ((is_categorical_dtype (data .dtype ) and
1899+ is_object_dtype (data .values .categories )) or
1900+ (is_object_dtype (data .dtype )))):
19051901 # it's neither a string series not a categorical series with
19061902 # strings inside the categories.
19071903 # this really should exclude all series with any non-string values
@@ -1910,23 +1906,27 @@ def _make_str_accessor(self):
19101906 raise AttributeError ("Can only use .str accessor with string "
19111907 "values, which use np.object_ dtype in "
19121908 "pandas" )
1913- elif isinstance (self , Index ):
1909+ elif isinstance (data , Index ):
19141910 # can't use ABCIndex to exclude non-str
19151911
19161912 # see scc/inferrence.pyx which can contain string values
19171913 allowed_types = ('string' , 'unicode' , 'mixed' , 'mixed-integer' )
1918- if self .inferred_type not in allowed_types :
1914+ if data .inferred_type not in allowed_types :
19191915 message = ("Can only use .str accessor with string values "
19201916 "(i.e. inferred_type is 'string', 'unicode' or "
19211917 "'mixed')" )
19221918 raise AttributeError (message )
1923- if self .nlevels > 1 :
1919+ if data .nlevels > 1 :
19241920 message = ("Can only use .str accessor with Index, not "
19251921 "MultiIndex" )
19261922 raise AttributeError (message )
1927- return StringMethods (self )
1923+ return StringMethods (data )
1924+
1925+
1926+ class StringAccessorMixin (object ):
1927+ """ Mixin to add a `.str` acessor to the class."""
19281928
1929- str = AccessorProperty (StringMethods , _make_str_accessor )
1929+ str = AccessorProperty (StringMethods )
19301930
19311931 def _dir_additions (self ):
19321932 return set ()
0 commit comments