@@ -442,8 +442,9 @@ def corrcoef(*args):
442
442
kw = dict (rowvar = False )
443
443
return npy .corrcoef (* args , ** kw )
444
444
445
- def polyfit (x , y , N ):
445
+ def polyfit (* args , ** kwargs ):
446
446
"""
447
+ def polyfit(x,y,N)
447
448
448
449
Do a best fit polynomial of order N of y to x. Return value is a
449
450
vector of polynomial coefficients [pk ... p1 p0]. Eg, for N=2
@@ -480,21 +481,13 @@ def polyfit(x,y,N):
480
481
See also polyval
481
482
482
483
"""
483
- x = npy .asarray (x , dtype = npy .float_ )
484
- #y = npy.asarray(y, dtype=npy.float_)
485
- #y.shape = (len(y),1)
486
- #X = npy.matrix(npy.vander(x, N+1))
487
- #Xt = npy.matrix(X.transpose())
488
- #c = npy.array(npy.linalg.inv(Xt*X)*Xt*y) # convert back to array
489
- #c.shape = (N+1,)
490
- #return c
491
- X = npy .vander (x , N + 1 )
492
- return npy .linalg .lstsq (X , y )[0 ]
484
+ warnings .warn ("use numpy.poyfit" , DeprecationWarning )
485
+ return npy .polyfit (* args , ** kw )
493
486
494
487
495
488
496
489
497
- def polyval (p , x ):
490
+ def polyval (* args , ** kwargs ):
498
491
"""
499
492
y = polyval(p,x)
500
493
@@ -510,14 +503,11 @@ def polyval(p,x):
510
503
See also polyfit
511
504
512
505
"""
513
- x = npy .asarray (x , dtype = npy .float_ )
514
- p = npy .asarray (p , dtype = npy .float_ ).reshape ((len (p ),1 ))
515
- X = npy .vander (x ,len (p ))
516
- y = npy .dot (X ,p )
517
- return y .reshape (x .shape )
506
+ warnings .warn ("use numpy.polyval" , DeprecationWarning )
507
+ return npy .polyval (* args , ** kw )
518
508
519
509
520
- def vander (x , N = None ):
510
+ def vander (* args , ** kwargs ):
521
511
"""
522
512
X = vander(x,N=None)
523
513
@@ -527,7 +517,7 @@ def vander(x,N=None):
527
517
528
518
"""
529
519
warnings .warn ("Use numpy.vander()" , DeprecationWarning )
530
- return npy .vander (x , N )
520
+ return npy .vander (* args , ** kwargs )
531
521
532
522
533
523
def donothing_callback (* args ):
@@ -1262,20 +1252,31 @@ def load(fname,comments='#',delimiter=None, converters=None,skiprows=0,
1262
1252
fh = cbook .to_filehandle (fname )
1263
1253
X = []
1264
1254
1255
+ if delimiter == ' ' :
1256
+ # space splitting is a special case since x.split() is what
1257
+ # you want, not x.split(' ')
1258
+ def splitfunc (x ):
1259
+ return x .split ()
1260
+ else :
1261
+ def splitfunc (x ):
1262
+ return x .split (delimiter )
1263
+
1264
+
1265
+
1265
1266
converterseq = None
1266
1267
for i ,line in enumerate (fh ):
1267
1268
if i < skiprows : continue
1268
1269
line = line .split (comments , 1 )[0 ].strip ()
1269
1270
if not len (line ): continue
1270
1271
if converterseq is None :
1271
1272
converterseq = [converters .get (j ,float )
1272
- for j ,val in enumerate (line . split ( delimiter ))]
1273
+ for j ,val in enumerate (splitfunc ( line ))]
1273
1274
if usecols is not None :
1274
1275
vals = line .split (delimiter )
1275
1276
row = [converterseq [j ](vals [j ]) for j in usecols ]
1276
1277
else :
1277
1278
row = [converterseq [j ](val )
1278
- for j ,val in enumerate (line . split ( delimiter ))]
1279
+ for j ,val in enumerate (splitfunc ( line ))]
1279
1280
thisLen = len (row )
1280
1281
X .append (row )
1281
1282
@@ -2281,7 +2282,7 @@ def __init__(self, precision=4):
2281
2282
FormatFloat .__init__ (self , precision , scale = 1e-6 )
2282
2283
2283
2284
2284
- class FormatDate (FormatString ):
2285
+ class FormatDate (FormatObj ):
2285
2286
def __init__ (self , fmt ):
2286
2287
self .fmt = fmt
2287
2288
@@ -2301,7 +2302,7 @@ def __init__(self, fmt='%Y-%m-%d %H:%M:%S'):
2301
2302
npy .float32 : FormatFloat (),
2302
2303
npy .float64 : FormatFloat (),
2303
2304
npy .object_ : FormatObj (),
2304
- npy .string_ : FormatString (),
2305
+ npy .string_ : FormatObj (),
2305
2306
}
2306
2307
2307
2308
def get_formatd (r , formatd = None ):
@@ -2658,15 +2659,21 @@ def foreach(model, path, iter, selected):
2658
2659
2659
2660
2660
2661
2661
- def rec2gtk (r , formatd = None , rownum = 0 ):
2662
+ def rec2gtk (r , formatd = None , rownum = 0 , autowin = True ):
2662
2663
"""
2663
2664
save record array r to excel pyExcelerator worksheet ws
2664
2665
starting at rownum. if ws is string like, assume it is a
2665
2666
filename and save to it
2666
2667
2667
2668
formatd is a dictionary mapping dtype name -> FormatXL instances
2668
2669
2669
- The next rownum after writing is returned
2670
+ This function creates a SortedStringsScrolledWindow (derived
2671
+ from gtk.ScrolledWindow) and returns it. if autowin is True,
2672
+ a gtk.Window is created, attached to the
2673
+ SortedStringsScrolledWindow instance, shown and returned. If
2674
+ autowin=False, the caller is responsible for adding the
2675
+ SortedStringsScrolledWindow instance to a gtk widget and
2676
+ showing it.
2670
2677
"""
2671
2678
2672
2679
@@ -2692,6 +2699,14 @@ def rec2gtk(r, formatd=None, rownum=0):
2692
2699
for row in r :
2693
2700
scroll .add_row (row )
2694
2701
2702
+
2703
+ if autowin :
2704
+ win = gtk .Window ()
2705
+ win .set_default_size (800 ,600 )
2706
+ win .add (scroll )
2707
+ win .show_all ()
2708
+ scroll .win = win
2709
+
2695
2710
return scroll
2696
2711
2697
2712
0 commit comments