55import sys
66
77from numpy .lib .format import read_array , write_array
8+ from numpy import NaN
89import numpy as np
910
1011from pandas .core .frame import DataFrame , _pfixed
@@ -147,7 +148,7 @@ def handleDict(data, index, columns, objects, dtype):
147148 K = len (columns )
148149
149150 values = np .empty ((N , K ), dtype = dtype )
150- values [:] = np . NaN
151+ values [:] = NaN
151152 else :
152153 raise Exception ('DataMatrix constructor not properly called!' )
153154
@@ -755,9 +756,9 @@ def _combineFrame(self, other, func):
755756 if not self and not other :
756757 return DataMatrix (index = newIndex )
757758 elif not self :
758- return other * np . NaN
759+ return other * NaN
759760 elif not other :
760- return self * np . NaN
761+ return self * NaN
761762
762763 myValues = myReindex .values
763764 if self .columns .equals (other .columns ):
@@ -774,7 +775,7 @@ def _combineFrame(self, other, func):
774775 else :
775776 T , N = len (newIndex ), len (newCols )
776777 resultMatrix = np .empty ((T , N ), dtype = self .values .dtype )
777- resultMatrix .fill (np . NaN )
778+ resultMatrix .fill (NaN )
778779
779780 myIndexer = [self .columns .indexMap [idx ] for idx in commonCols ]
780781 hisIndexer = [hisCols .indexMap [idx ] for idx in commonCols ]
@@ -804,11 +805,15 @@ def _combineSeries(self, other, func):
804805 resultMatrix = func (myReindex .values .T , other ).T
805806 else :
806807 if len (other ) == 0 :
807- return self * np .NaN
808+ return self * NaN
809+
810+ newCols = self .columns .union (other .index )
808811
809812 # Operate column-wise
810- other = other .reindex (self .columns ).view (np .ndarray )
811- resultMatrix = func (self .values , other )
813+ this = self .reindex (columns = newCols )
814+ other = other .reindex (newCols ).values ()
815+
816+ resultMatrix = func (this .values , other )
812817
813818 # TODO: deal with objects
814819 return DataMatrix (resultMatrix , index = newIndex , columns = newCols )
@@ -1190,7 +1195,7 @@ def merge(self, otherFrame, on=None):
11901195 fillVec , mask = tseries .getMergeVec (self [on ], indexMap )
11911196
11921197 tmpMatrix = otherM .take (fillVec , axis = 0 )
1193- tmpMatrix [- mask ] = np . NaN
1198+ tmpMatrix [- mask ] = NaN
11941199
11951200 seriesDict = dict ((col , tmpMatrix [:, j ])
11961201 for j , col in enumerate (otherFrame .columns ))
@@ -1201,7 +1206,7 @@ def merge(self, otherFrame, on=None):
12011206 objM = objects .asMatrix ()
12021207
12031208 tmpMat = objM .take (fillVec , axis = 0 )
1204- tmpMat [- mask ] = np . NaN
1209+ tmpMat [- mask ] = NaN
12051210 objDict = dict ((col , tmpMat [:, j ])
12061211 for j , col in enumerate (objects .columns ))
12071212
@@ -1229,7 +1234,7 @@ def _reindex_index(self, index, method):
12291234 index .indexMap , method )
12301235
12311236 tmpMatrix = self .values .take (fillVec , axis = 0 )
1232- tmpMatrix [- mask ] = np . NaN
1237+ tmpMatrix [- mask ] = NaN
12331238
12341239 if self .objects is not None and len (self .objects .columns ) > 0 :
12351240 newObjects = self .objects .reindex (index )
@@ -1252,37 +1257,11 @@ def _reindex_columns(self, columns):
12521257 columns .indexMap , '' )
12531258
12541259 newValues = self .values .take (indexer , axis = 1 )
1255- newValues [:, - mask ] = np . NaN
1260+ newValues [:, - mask ] = NaN
12561261
12571262 return DataMatrix (newValues , index = self .index , columns = columns ,
12581263 objects = self .objects )
12591264
1260-
1261- def _withColumns (self , columns ):
1262- """
1263- Utility method, force values matrix to have particular columns
1264- Can make this as cute as we like
1265- """
1266- if len (columns ) == 0 :
1267- return DataMatrix (index = self .index )
1268-
1269- T , N = len (self .index ), len (columns )
1270-
1271- resultMatrix = np .empty ((T , N ), dtype = self .values .dtype )
1272- resultMatrix .fill (np .NaN )
1273-
1274- if not isinstance (columns , Index ):
1275- columns = Index (columns )
1276-
1277- overlap = self .columns .intersection (columns )
1278- thisIndexer = [self .columns .indexMap [col ] for col in overlap ]
1279- resultIndexer = [columns .indexMap [idx ] for idx in overlap ]
1280-
1281- resultMatrix [:, resultIndexer ] = self .values [:, thisIndexer ]
1282-
1283- return DataMatrix (resultMatrix , index = self .index , columns = columns ,
1284- objects = self .objects )
1285-
12861265 @property
12871266 def T (self ):
12881267 """
@@ -1324,17 +1303,27 @@ def shift(self, periods, offset=None, timeRule=None):
13241303 if timeRule is not None and offset is None :
13251304 offset = datetools .getOffset (timeRule )
13261305
1306+ N = len (self )
1307+
13271308 if offset is None :
1309+ newIndex = self .index
1310+ indexer = np .zeros (N , dtype = int )
13281311 if periods > 0 :
1329- newIndex = self .index [periods :]
1330- newValues = self .values [:- periods ].copy ()
1312+ indexer [periods :] = np .arange (N - periods )
1313+ newValues = self .values .take (indexer , axis = 0 )
1314+ newValues [:periods ] = NaN
13311315 else :
1332- newIndex = self .index [:periods ]
1333- newValues = self .values [- periods :].copy ()
1316+ indexer [:periods ] = np .arange (- periods , N )
1317+ newValues = self .values .take (indexer , axis = 0 )
1318+ newValues [periods :] = NaN
13341319 else :
13351320 offset = periods * offset
1336- newIndex = Index ([idx + offset for idx in self .index ])
1321+ newIndex = Index ([x + offset for x in self .index ])
13371322 newValues = self .values .copy ()
1323+
1324+ if self .objects is not None :
1325+ pass
1326+
13381327 return DataMatrix (data = newValues , index = newIndex , columns = self .columns )
13391328
13401329 def apply (self , func , axis = 0 ):
0 commit comments