Ticket #7494: trac_7494.patch
File trac_7494.patch, 5.1 KB (added by , 8 years ago) 


sage/finance/stock.py
# HG changeset patch # User William Stein <wstein@gmail.com> # Date 1314168158 25200 # Node ID 9ac9e0edc71d79e9c181c3bb0520bf2e6fa55aa0 # Parent 43d128c82f60965828f9fc26207465b1ad5a36f8 trac 7494: remove SAGE_ROOT/examples diff git a/sage/finance/stock.py b/sage/finance/stock.py
a b 424 424 ``AAPLminutely.csv``. One can load this information into a Stock 425 425 object like so. Note that the path must be explicit:: 426 426 427 sage: finance.Stock('aapl').load_from_file(SAGE_ROOT + '/examples/finance/AAPLminutely.csv')[:5] 427 sage: filename = tmp_filename() + '.csv' 428 sage: open(filename,'w').write("Date,Open,High,Low,Close,Volume\n1212405780,187.80,187.80,187.80,187.80,100\n1212407640,187.75,188.00,187.75,188.00,2000\n1212407700,188.00,188.00,188.00,188.00,1000\n1212408000,188.00,188.11,188.00,188.00,2877\n1212408060,188.00,188.00,188.00,188.00,687") 429 sage: finance.Stock('aapl').load_from_file(filename)[:5] 428 430 [ 429 431 1212408060 188.00 188.00 188.00 188.00 687, 430 432 1212408000 188.00 188.11 188.00 188.00 2877, … … 440 442 example, we can initialize a Stock object with the symbol ``'goog'``, 441 443 but load data from ``'aapl'`` stock prices:: 442 444 443 sage: finance.Stock('goog').load_from_file( SAGE_ROOT + '/examples/finance/AAPLminutely.csv')[:5]445 sage: finance.Stock('goog').load_from_file(filename)[:5] 444 446 [ 445 447 1212408060 188.00 188.00 188.00 188.00 687, 446 448 1212408000 188.00 188.11 188.00 188.00 2877, … … 452 454 This tests a file that doesn't exist:: 453 455 454 456 sage: finance.Stock("AAPL").load_from_file("I am not a file") 455 Bad path or file name 457 Traceback (most recent call last): 458 ... 459 IOError: [Errno 2] No such file or directory: 'I am not a file' 456 460 """ 457 try: 458 file_obj = open(file, 'r') 459 R = file_obj.read(); 460 self.__historical = self._load_from_csv(R) 461 file_obj.close() 462 return self.__historical 463 except IOError, msg: 464 print "Bad path or file name" 461 file_obj = open(file, 'r') 462 R = file_obj.read(); 463 self.__historical = self._load_from_csv(R) 464 file_obj.close() 465 return self.__historical 466 465 467 466 468 def _load_from_csv(self, R): 467 469 """ … … 469 471 470 472 This indirectly tests ``_load_from_csv()``:: 471 473 472 sage: finance.Stock('aapl').load_from_file(SAGE_ROOT + "/examples/finance/AAPLminutely.csv") 474 sage: filename = tmp_filename() + '.csv' 475 sage: open(filename,'w').write("Date,Open,High,Low,Close,Volume\n1212405780,187.80,187.80,187.80,187.80,100\n1212407640,187.75,188.00,187.75,188.00,2000\n1212407700,188.00,188.00,188.00,188.00,1000\n1212408000,188.00,188.11,188.00,188.00,2877\n1212408060,188.00,188.00,188.00,188.00,687") 476 sage: finance.Stock('aapl').load_from_file(filename) 473 477 [ 474 478 1212408060 188.00 188.00 188.00 188.00 687, 475 479 1212408000 188.00 188.11 188.00 188.00 2877, 
sage/misc/hg.py
diff git a/sage/misc/hg.py b/sage/misc/hg.py
a b 1259 1259 obj_name='extcode') 1260 1260 1261 1261 1262 hg_examples = HG('%s/data/examples'%SAGE_ROOT,1263 'Sage Examples',1264 pull_url='%s/examples/'%SAGE_INCOMING_SERVER,1265 push_url='%s/examples/'%SAGE_OUTGOING_SERVER,1266 obj_name='examples')1267 1268 1262 hg_root = HG(SAGE_ROOT, 1269 1263 'Sage Root', 1270 1264 pull_url=SAGE_INCOMING_SERVER, 
sage/misc/inline_fortran.py
diff git a/sage/misc/inline_fortran.py b/sage/misc/inline_fortran.py
a b 21 21 22 22 def eval(self,x,globals=None, locals=None): 23 23 """ 24 EXAMPLES: 25 sage: from sage.misc.inline_fortran import InlineFortran 26 sage: import os 27 sage: s = open(os.environ['SAGE_ROOT'] + '/examples/fortran/FIB1.F').read() 24 EXAMPLES:: 25 26 sage: from sage.misc.inline_fortran import InlineFortran, _example 28 27 sage: test_fortran = InlineFortran(globals()) # optional  fortran 29 sage: test_fortran( s)# optional  fortran28 sage: test_fortran(_example) # optional  fortran 30 29 sage: import numpy 31 30 sage: n = numpy.array(range(10),dtype=float) 32 31 sage: fib(n,int(10)) # optional  fortran … … 101 100 def add_library_path(self,s): 102 101 self.library_paths.append(s) 103 102 103 104 _example = """ 105 C FILE: FIB1.F 106 SUBROUTINE FIB(A,N) 107 C 108 C CALCULATE FIRST N FIBONACCI NUMBERS 109 C 110 INTEGER N 111 REAL*8 A(N) 112 DO I=1,N 113 IF (I.EQ.1) THEN 114 A(I) = 0.0D0 115 ELSEIF (I.EQ.2) THEN 116 A(I) = 1.0D0 117 ELSE 118 A(I) = A(I1) + A(I2) 119 ENDIF 120 ENDDO 121 END 122 C END FILE FIB1.F 123 """