@@ -86,16 +86,22 @@ def __unicode__(self):
8686 # Should be overwritten by base classes
8787 return object .__repr__ (self )
8888
89- def _local_dir (self ):
90- """ provide addtional __dir__ for this object """
91- return []
89+ def _dir_additions (self ):
90+ """ add addtional __dir__ for this object """
91+ return set ()
92+
93+ def _dir_deletions (self ):
94+ """ delete unwanted __dir__ for this object """
95+ return set ()
9296
9397 def __dir__ (self ):
9498 """
9599 Provide method name lookup and completion
96100 Only provide 'public' methods
97101 """
98- return list (sorted (list (set (dir (type (self )) + self ._local_dir ()))))
102+ rv = set (dir (type (self )))
103+ rv = (rv - self ._dir_deletions ()) | self ._dir_additions ()
104+ return sorted (rv )
99105
100106 def _reset_cache (self , key = None ):
101107 """
@@ -498,8 +504,7 @@ def searchsorted(self, key, side='left'):
498504 #### needs tests/doc-string
499505 return self .values .searchsorted (key , side = side )
500506
501- # string methods
502- def _make_str_accessor (self ):
507+ def _check_str_accessor (self ):
503508 from pandas .core .series import Series
504509 from pandas .core .index import Index
505510 if isinstance (self , Series ) and not com .is_object_dtype (self .dtype ):
@@ -512,10 +517,24 @@ def _make_str_accessor(self):
512517 elif isinstance (self , Index ) and self .inferred_type != 'string' :
513518 raise AttributeError ("Can only use .str accessor with string "
514519 "values (i.e. inferred_type is 'string')" )
520+
521+ # string methods
522+ def _make_str_accessor (self ):
523+ self ._check_str_accessor ()
515524 return StringMethods (self )
516525
517526 str = AccessorProperty (StringMethods , _make_str_accessor )
518527
528+ def _dir_additions (self ):
529+ return set ()
530+
531+ def _dir_deletions (self ):
532+ try :
533+ self ._check_str_accessor ()
534+ except AttributeError :
535+ return set (['str' ])
536+ return set ()
537+
519538 _shared_docs ['drop_duplicates' ] = (
520539 """Return %(klass)s with duplicate values removed
521540
0 commit comments