SERVING THE QUANTITATIVE FINANCE COMMUNITY

 
User avatar
FaridMoussaoui
Posts: 456
Joined: June 20th, 2008, 10:05 am
Location: Genève, Genf, Ginevra, Geneva

Re: Python tricks

October 10th, 2019, 3:40 pm

that's python IDE is easier
 
User avatar
Cuchulainn
Posts: 60501
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Re: Python tricks

October 11th, 2019, 7:51 am

that's python IDE is easier
I sugested pyCharm. My student loves it! No looking back, goodbye VS and parallels for her. We keep the infrastructure threshold low. The rest is plain sailing.
Merci, Farid.
http://www.datasimfinancial.com
http://www.datasim.nl

Approach your problem from the right end and begin with the answers. Then one day, perhaps you will find the final question..
R. van Gulik
 
User avatar
Cuchulainn
Posts: 60501
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Re: Python tricks

October 17th, 2019, 1:56 pm

Is this a bug in Python?
import pandas as pd
from pandas import datetime, period_range

#compiles
#myRange = pd.period_range('2000-01-01', periods=12, freq='T')
#ts  = pd.Series(range(12), index=myRange)

#NOT compile
range = pd.period_range('2000-01-01', periods=12, freq='T')
ts  = pd.Series(range(12), index=range)

ts.index = ts.index.astype('datetime64[ns]')
data_higher_freq = ts.resample('5T').sum()
http://www.datasimfinancial.com
http://www.datasim.nl

Approach your problem from the right end and begin with the answers. Then one day, perhaps you will find the final question..
R. van Gulik
 
User avatar
FaridMoussaoui
Posts: 456
Joined: June 20th, 2008, 10:05 am
Location: Genève, Genf, Ginevra, Geneva

Re: Python tricks

October 17th, 2019, 2:52 pm

Is this a bug in Python?
Isn't python, it is the developer. What about using a square bracket instead of a parenthese .....
 
User avatar
Cuchulainn
Posts: 60501
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Re: Python tricks

October 17th, 2019, 4:51 pm

Even more interesting I accidentally had a range() function and this is the one that resample() sees. Ouch
Very bad.I am accidentally or deliberately overriding what is in essence an (undocumented) Python keyword 'range'.

Q: The ability to override core Python functions with impunity,feature or bug?

Code:
 
def range(i):
    print ("range")
    return 1/0

 
http://www.datasimfinancial.com
http://www.datasim.nl

Approach your problem from the right end and begin with the answers. Then one day, perhaps you will find the final question..
R. van Gulik
 
User avatar
Cuchulainn
Posts: 60501
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Re: Python tricks

October 17th, 2019, 4:58 pm

Is this a bug in Python?
Isn't python, it is the developer. What about using a square bracket instead of a parenthese .....
range is a function, not an object
?
http://www.datasimfinancial.com
http://www.datasim.nl

Approach your problem from the right end and begin with the answers. Then one day, perhaps you will find the final question..
R. van Gulik
 
User avatar
tagoma
Topic Author
Posts: 18280
Joined: February 21st, 2010, 12:58 pm

Re: Python tricks

October 20th, 2019, 8:49 am

Is this a bug in Python?
Isn't python, it is the developer. What about using a square bracket instead of a parenthese .....
range is a function, not an object
?
Python allows built-in functions overloading. Bad or good is mental masturbation. That's just the way it is. Programmer is supposed to have come through the list of these built-in functions at some point, and understands it is usually bad practice to use those name to create object/functions/etc. To somewhat circumvent the issue, programmer can use scope/namespace tricks.

import builtins
builtins.range(10)
#range(0, 10)


 
 
User avatar
Cuchulainn
Posts: 60501
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Re: Python tricks

October 20th, 2019, 9:56 am

Nice. So, one can put functions and so on in modules which is good practice. System decomposition into independent and loosely coupled modules is recommended before jumping head first into coding marathons.
http://www.datasimfinancial.com
http://www.datasim.nl

Approach your problem from the right end and begin with the answers. Then one day, perhaps you will find the final question..
R. van Gulik
 
User avatar
ISayMoo
Posts: 2206
Joined: September 30th, 2015, 8:30 pm

Re: Python tricks

November 1st, 2019, 4:45 pm

 
User avatar
tagoma
Topic Author
Posts: 18280
Joined: February 21st, 2010, 12:58 pm

Re: Python tricks

November 23rd, 2019, 1:23 pm

Python 3.8 introduced the Walrus operator.
What are the cons according to you Wilmotters?
ABOUT WILMOTT

PW by JB

Wilmott.com has been "Serving the Quantitative Finance Community" since 2001. Continued...


Twitter LinkedIn Instagram

JOBS BOARD

JOBS BOARD

Looking for a quant job, risk, algo trading,...? Browse jobs here...


GZIP: On