Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #20353
| Date | 2012-02-13 18:53 +0100 |
|---|---|
| From | Fabrizio Pollastri <f.pollastri@inrim.it> |
| Subject | Re: package extension problem |
| References | <19027093.1215.1329153496662.JavaMail.geo-discussion-forums@ynel5> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.5765.1329155611.27778.python-list@python.org> (permalink) |
Ok. To be more clear, consider the real python package Pandas.
This package defines a Series class and a DataFrame class.
The DataFrame is a matrix that can have columns of
different type.
If I write
import pandas as pd
df = pd.DataFrame({'A':[1,2,3],'B':[4,5,6]})
a data frame with two cols named A and B is created.
If I write
col_A = df['A']
the returned col_A is an instance of Series.
Now , let suppose that I want to extend some functionality of pandas
by adding new methods to both Series and DataFrame classes.
One way to do this is to redefine this classes in a new package
(new_pandas) as follow
import pandas as pd
class Series(pd.Series):
...
add new methods
...
class DataFrame(pd.DataFrame):
...
add new methods
...
When I use the new package as a pandas substitute and write
import new_pandas as np
df = np.DataFrame({'A':[1,2,3],'B':[4,5,6]})
col_A = df['A']
col_A is an instance of the original pandas and not of the new pandas,
losing all the added functionality.
Fabrizio
Now, how can I add new methods to extend the functionality of pandas
classes Series and DataFrame
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
package extension problem Fabrizio Pollastri <f.pollastri@inrim.it> - 2012-02-12 19:46 +0100
Re: package extension problem Miki Tebeka <miki.tebeka@gmail.com> - 2012-02-13 09:18 -0800
Re: package extension problem Fabrizio Pollastri <f.pollastri@inrim.it> - 2012-02-13 18:53 +0100
Re: package extension problem Miki Tebeka <miki.tebeka@gmail.com> - 2012-02-13 09:58 -0800
Re: package extension problem Terry Reedy <tjreedy@udel.edu> - 2012-02-13 14:12 -0500
Re: package extension problem Miki Tebeka <miki.tebeka@gmail.com> - 2012-02-13 09:58 -0800
Re: package extension problem Peter Otten <__peter__@web.de> - 2012-02-13 19:28 +0100
Re: package extension problem Miki Tebeka <miki.tebeka@gmail.com> - 2012-02-13 09:18 -0800
csiph-web