1
1
# pylint: disable=W0231,E1101
2
2
import warnings
3
- from pandas import compat
4
- import itertools
5
3
import operator
6
4
import weakref
7
5
import numpy as np
8
6
import pandas .lib as lib
9
- from pandas .core .base import PandasObject
10
7
8
+ from pandas .core .base import PandasObject
11
9
from pandas .core .index import Index , MultiIndex , _ensure_index
12
10
import pandas .core .indexing as indexing
13
11
from pandas .core .indexing import _maybe_convert_indices
14
12
from pandas .tseries .index import DatetimeIndex
15
13
from pandas .core .internals import BlockManager
16
- import pandas .lib as lib
17
- from pandas .util import py3compat
18
14
import pandas .core .common as com
15
+ from pandas import compat
19
16
from pandas .compat import map , zip
20
17
from pandas .core .common import (isnull , notnull , is_list_like ,
21
18
_values_from_object ,
22
19
_infer_dtype_from_scalar , _maybe_promote )
23
- from pandas .core .base import PandasObject
24
-
25
20
26
21
class NDFrame (PandasObject ):
27
22
@@ -78,10 +73,6 @@ def _init_mgr(self, mgr, axes=None, dtype=None, copy=False):
78
73
def _constructor (self ):
79
74
raise NotImplementedError
80
75
81
- def __hash__ (self ):
82
- raise TypeError ('{0!r} objects are mutable, thus they cannot be'
83
- ' hashed' .format (self .__class__ .__name__ ))
84
-
85
76
def __unicode__ (self ):
86
77
# unicode representation based upon iterating over self
87
78
# (since, by definition, `PandasContainers` are iterable)
@@ -111,12 +102,12 @@ def _setup_axes(
111
102
"""
112
103
113
104
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 ))
115
106
cls ._AXIS_LEN = len (axes )
116
107
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 ))
120
111
cls ._AXIS_SLICEMAP = slicers or None
121
112
cls ._AXIS_REVERSED = axes_are_reversed
122
113
@@ -271,23 +262,6 @@ def axes(self):
271
262
the block manager shows then reversed """
272
263
return [self ._get_axis (a ) for a in self ._AXIS_ORDERS ]
273
264
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
-
291
265
@property
292
266
def ndim (self ):
293
267
return self ._data .ndim
@@ -445,9 +419,6 @@ def rename_axis(self, mapper, axis=0, copy=True):
445
419
def _indexed_same (self , other ):
446
420
return all ([self ._get_axis (a ).equals (other ._get_axis (a )) for a in self ._AXIS_ORDERS ])
447
421
448
- def reindex (self , * args , ** kwds ):
449
- raise NotImplementedError
450
-
451
422
def __neg__ (self ):
452
423
arr = operator .neg (_values_from_object (self ))
453
424
return self ._wrap_array (arr , self .axes , copy = False )
@@ -460,7 +431,8 @@ def __invert__(self):
460
431
# Iteration
461
432
462
433
def __hash__ (self ):
463
- raise TypeError
434
+ raise TypeError ('{0!r} objects are mutable, thus they cannot be'
435
+ ' hashed' .format (self .__class__ .__name__ ))
464
436
465
437
def __iter__ (self ):
466
438
"""
@@ -483,7 +455,6 @@ def iterkv(self, *args, **kwargs):
483
455
"release, use ``iteritems`` instead." , DeprecationWarning )
484
456
return self .iteritems (* args , ** kwargs )
485
457
486
-
487
458
def __len__ (self ):
488
459
"""Returns length of info axis """
489
460
return len (self ._info_axis )
@@ -1142,7 +1113,7 @@ def filter(self, items=None, like=None, regex=None, axis=None):
1142
1113
if items is not None :
1143
1114
return self .reindex (** {axis_name : [r for r in items if r in axis_values ]})
1144
1115
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 )
1146
1117
else like in str (x ))
1147
1118
return self .select (matchf , axis = axis_name )
1148
1119
elif regex :
@@ -1285,6 +1256,7 @@ def get_dtype_counts(self):
1285
1256
1286
1257
def get_ftype_counts (self ):
1287
1258
""" return the counts of ftypes in this frame """
1259
+ from pandas import Series
1288
1260
return Series (self ._data .get_ftype_counts ())
1289
1261
1290
1262
def as_blocks (self , columns = None ):
@@ -1446,7 +1418,7 @@ def fillna(self, value=None, method=None, axis=0, inplace=False,
1446
1418
'by column' )
1447
1419
1448
1420
result = self if inplace else self .copy ()
1449
- for k , v in value .iteritems ():
1421
+ for k , v in compat .iteritems (value ):
1450
1422
if k not in result :
1451
1423
continue
1452
1424
obj = result [k ]
@@ -1595,7 +1567,7 @@ def is_dictlike(x):
1595
1567
regex = True
1596
1568
1597
1569
items = to_replace .items ()
1598
- keys , values = itertools . izip (* items )
1570
+ keys , values = zip (* items )
1599
1571
1600
1572
are_mappings = [is_dictlike (v ) for v in values ]
1601
1573
@@ -1629,7 +1601,7 @@ def is_dictlike(x):
1629
1601
if is_dictlike (to_replace ):
1630
1602
if is_dictlike (value ): # {'A' : NA} -> {'A' : 0}
1631
1603
new_data = self ._data
1632
- for c , src in to_replace .iteritems ():
1604
+ for c , src in compat .iteritems (to_replace ):
1633
1605
if c in value and c in self :
1634
1606
new_data = new_data .replace (src , value [c ],
1635
1607
filter = [c ],
@@ -1639,7 +1611,7 @@ def is_dictlike(x):
1639
1611
# {'A': NA} -> 0
1640
1612
elif not isinstance (value , (list , np .ndarray )):
1641
1613
new_data = self ._data
1642
- for k , src in to_replace .iteritems ():
1614
+ for k , src in compat .iteritems (to_replace ):
1643
1615
if k in self :
1644
1616
new_data = new_data .replace (src , value ,
1645
1617
filter = [k ],
@@ -1679,7 +1651,7 @@ def is_dictlike(x):
1679
1651
if is_dictlike (value ): # NA -> {'A' : 0, 'B' : -1}
1680
1652
new_data = self ._data
1681
1653
1682
- for k , v in value .iteritems ():
1654
+ for k , v in compat .iteritems (value ):
1683
1655
if k in self :
1684
1656
new_data = new_data .replace (to_replace , v ,
1685
1657
filter = [k ],
@@ -1729,7 +1701,7 @@ def interpolate(self, to_replace, method='pad', axis=0, inplace=False,
1729
1701
1730
1702
method = com ._clean_fill_method (method )
1731
1703
1732
- if isinstance (to_replace , (dict , Series )):
1704
+ if isinstance (to_replace , (dict , com . ABCSeries )):
1733
1705
if axis == 0 :
1734
1706
return self .replace (to_replace , method = method , inplace = inplace ,
1735
1707
limit = limit , axis = axis )
0 commit comments