11# pylint: disable=W0231,E1101
22import warnings
3- from pandas import compat
4- import itertools
53import operator
64import weakref
75import numpy as np
86import pandas .lib as lib
9- from pandas .core .base import PandasObject
107
8+ from pandas .core .base import PandasObject
119from pandas .core .index import Index , MultiIndex , _ensure_index
1210import pandas .core .indexing as indexing
1311from pandas .core .indexing import _maybe_convert_indices
1412from pandas .tseries .index import DatetimeIndex
1513from pandas .core .internals import BlockManager
16- import pandas .lib as lib
17- from pandas .util import py3compat
1814import pandas .core .common as com
15+ from pandas import compat
1916from pandas .compat import map , zip
2017from pandas .core .common import (isnull , notnull , is_list_like ,
2118 _values_from_object ,
2219 _infer_dtype_from_scalar , _maybe_promote )
23- from pandas .core .base import PandasObject
24-
2520
2621class NDFrame (PandasObject ):
2722
@@ -78,10 +73,6 @@ def _init_mgr(self, mgr, axes=None, dtype=None, copy=False):
7873 def _constructor (self ):
7974 raise NotImplementedError
8075
81- def __hash__ (self ):
82- raise TypeError ('{0!r} objects are mutable, thus they cannot be'
83- ' hashed' .format (self .__class__ .__name__ ))
84-
8576 def __unicode__ (self ):
8677 # unicode representation based upon iterating over self
8778 # (since, by definition, `PandasContainers` are iterable)
@@ -111,12 +102,12 @@ def _setup_axes(
111102 """
112103
113104 cls ._AXIS_ORDERS = axes
114- cls ._AXIS_NUMBERS = dict ([ (a , i ) for i , a in enumerate (axes )] )
105+ cls ._AXIS_NUMBERS = dict ((a , i ) for i , a in enumerate (axes ))
115106 cls ._AXIS_LEN = len (axes )
116107 cls ._AXIS_ALIASES = aliases or dict ()
117- cls ._AXIS_IALIASES = dict ([ (v , k )
118- for k , v in cls ._AXIS_ALIASES .items ()] )
119- cls ._AXIS_NAMES = dict ([( i , a ) for i , a in enumerate (axes )] )
108+ cls ._AXIS_IALIASES = dict ((v , k )
109+ for k , v in cls ._AXIS_ALIASES .items ())
110+ cls ._AXIS_NAMES = dict (enumerate (axes ))
120111 cls ._AXIS_SLICEMAP = slicers or None
121112 cls ._AXIS_REVERSED = axes_are_reversed
122113
@@ -271,23 +262,6 @@ def axes(self):
271262 the block manager shows then reversed """
272263 return [self ._get_axis (a ) for a in self ._AXIS_ORDERS ]
273264
274- def _construct_axes_dict (self , axes = None , ** kwargs ):
275- """ return an axes dictionary for myself """
276- d = dict ([(a , getattr (self , a )) for a in (axes or self ._AXIS_ORDERS )])
277- d .update (kwargs )
278- return d
279-
280- @staticmethod
281- def _construct_axes_dict_from (self , axes , ** kwargs ):
282- """ return an axes dictionary for the passed axes """
283- d = dict ([(a , ax ) for a , ax in zip (self ._AXIS_ORDERS , axes )])
284- d .update (kwargs )
285- return d
286-
287- @property
288- def values (self ):
289- return self ._data .as_matrix ()
290-
291265 @property
292266 def ndim (self ):
293267 return self ._data .ndim
@@ -445,9 +419,6 @@ def rename_axis(self, mapper, axis=0, copy=True):
445419 def _indexed_same (self , other ):
446420 return all ([self ._get_axis (a ).equals (other ._get_axis (a )) for a in self ._AXIS_ORDERS ])
447421
448- def reindex (self , * args , ** kwds ):
449- raise NotImplementedError
450-
451422 def __neg__ (self ):
452423 arr = operator .neg (_values_from_object (self ))
453424 return self ._wrap_array (arr , self .axes , copy = False )
@@ -460,7 +431,8 @@ def __invert__(self):
460431 # Iteration
461432
462433 def __hash__ (self ):
463- raise TypeError
434+ raise TypeError ('{0!r} objects are mutable, thus they cannot be'
435+ ' hashed' .format (self .__class__ .__name__ ))
464436
465437 def __iter__ (self ):
466438 """
@@ -483,7 +455,6 @@ def iterkv(self, *args, **kwargs):
483455 "release, use ``iteritems`` instead." , DeprecationWarning )
484456 return self .iteritems (* args , ** kwargs )
485457
486-
487458 def __len__ (self ):
488459 """Returns length of info axis """
489460 return len (self ._info_axis )
@@ -1142,7 +1113,7 @@ def filter(self, items=None, like=None, regex=None, axis=None):
11421113 if items is not None :
11431114 return self .reindex (** {axis_name : [r for r in items if r in axis_values ]})
11441115 elif like :
1145- matchf = lambda x : (like in x if isinstance (x , basestring )
1116+ matchf = lambda x : (like in x if isinstance (x , compat . string_types )
11461117 else like in str (x ))
11471118 return self .select (matchf , axis = axis_name )
11481119 elif regex :
@@ -1285,6 +1256,7 @@ def get_dtype_counts(self):
12851256
12861257 def get_ftype_counts (self ):
12871258 """ return the counts of ftypes in this frame """
1259+ from pandas import Series
12881260 return Series (self ._data .get_ftype_counts ())
12891261
12901262 def as_blocks (self , columns = None ):
@@ -1446,7 +1418,7 @@ def fillna(self, value=None, method=None, axis=0, inplace=False,
14461418 'by column' )
14471419
14481420 result = self if inplace else self .copy ()
1449- for k , v in value .iteritems ():
1421+ for k , v in compat .iteritems (value ):
14501422 if k not in result :
14511423 continue
14521424 obj = result [k ]
@@ -1595,7 +1567,7 @@ def is_dictlike(x):
15951567 regex = True
15961568
15971569 items = to_replace .items ()
1598- keys , values = itertools . izip (* items )
1570+ keys , values = zip (* items )
15991571
16001572 are_mappings = [is_dictlike (v ) for v in values ]
16011573
@@ -1629,7 +1601,7 @@ def is_dictlike(x):
16291601 if is_dictlike (to_replace ):
16301602 if is_dictlike (value ): # {'A' : NA} -> {'A' : 0}
16311603 new_data = self ._data
1632- for c , src in to_replace .iteritems ():
1604+ for c , src in compat .iteritems (to_replace ):
16331605 if c in value and c in self :
16341606 new_data = new_data .replace (src , value [c ],
16351607 filter = [c ],
@@ -1639,7 +1611,7 @@ def is_dictlike(x):
16391611 # {'A': NA} -> 0
16401612 elif not isinstance (value , (list , np .ndarray )):
16411613 new_data = self ._data
1642- for k , src in to_replace .iteritems ():
1614+ for k , src in compat .iteritems (to_replace ):
16431615 if k in self :
16441616 new_data = new_data .replace (src , value ,
16451617 filter = [k ],
@@ -1679,7 +1651,7 @@ def is_dictlike(x):
16791651 if is_dictlike (value ): # NA -> {'A' : 0, 'B' : -1}
16801652 new_data = self ._data
16811653
1682- for k , v in value .iteritems ():
1654+ for k , v in compat .iteritems (value ):
16831655 if k in self :
16841656 new_data = new_data .replace (to_replace , v ,
16851657 filter = [k ],
@@ -1729,7 +1701,7 @@ def interpolate(self, to_replace, method='pad', axis=0, inplace=False,
17291701
17301702 method = com ._clean_fill_method (method )
17311703
1732- if isinstance (to_replace , (dict , Series )):
1704+ if isinstance (to_replace , (dict , com . ABCSeries )):
17331705 if axis == 0 :
17341706 return self .replace (to_replace , method = method , inplace = inplace ,
17351707 limit = limit , axis = axis )
0 commit comments