Skip to content

Subclassing improvements #12308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
Closed

Conversation

cldy
Copy link

@cldy cldy commented Feb 12, 2016

Addresses indexing issues related to subclassing (#11559).

Also made some changes to base, groupby, reshape, strings.
So for example, if df was a SubclassedDataFrame and s was a SubclassedSeries
df.groupby('A').apply(lambda x: x)
and
s.value_counts()
would return SubclassedDataFrame and SubclassedSeries instances, respectively.

@jreback jreback added Indexing Related to indexing on series/frames, not to indexes themselves Compat pandas objects compatability with Numpy or Python functions labels Feb 12, 2016
@@ -279,7 +279,12 @@ def _isnull_ndarraylike(obj):
# box
if isinstance(obj, ABCSeries):
from pandas import Series
result = Series(result, index=obj.index, name=obj.name, copy=False)
if isinstance(obj, Series):
result = obj._constructor_sliced(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lots of repeatitive code here. I don't think you need anything except replace Series with obj._constructor_sliced no?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, changed that.

@cldy
Copy link
Author

cldy commented Feb 18, 2016

So I have made most of the changes you suggested (also see comments above).

  • removed an unnecessary constructor in generic.py and an unnecessary if/then in common.py
  • constructors in groupby and merge are now properties
  • unstack logic is handled in unstack instead of series.py

I do not really understand what you mean by your comment on the change in ops.py, could you explain?

@jreback
Copy link
Contributor

jreback commented Feb 18, 2016

@cldy thanks for this. I will have a closer look prob next week.

@jreback jreback added this to the 0.18.1 milestone Feb 18, 2016
@jreback
Copy link
Contributor

jreback commented Mar 12, 2016

pls rebase/update

@jreback
Copy link
Contributor

jreback commented Mar 16, 2016

btw, you will want to squash this down and simply rebase on master to fast-forward yourself.

@codecov-io
Copy link

codecov-io commented Mar 16, 2016

Current coverage is 88.69%

Merging #12308 into master will increase coverage by 4.46%

@@             master   #12308   diff @@
========================================
  Files           138      276     +138   
  Lines         50712   134409   +83697   
  Methods           0        0            
  Branches          0        0            
========================================
+ Hits          42714   119218   +76504   
- Misses         7998    15191    +7193   
  Partials          0        0            

Powered by Codecov. Last updated by 2e3c82e...297ffe0

@cldy
Copy link
Author

cldy commented Mar 18, 2016

Sorrry this is taking so long. The rebase and squash turned out to be more complicated than expected, but is now done (locally).

I am still at a bit of a loss as to why the Travis build fails. The error is apparently due to the locale setting zh_CN.GB18030 (No such file or directory). I will have a closer look at this at the beginning of next week, but would be grateful for a hint.

@jreback
Copy link
Contributor

jreback commented Mar 18, 2016

@cldy you need to rebase on master. you should only have your commits here.

@cldy cldy force-pushed the subclassing_fixes2 branch 2 times, most recently from 6008ae0 to cbea137 Compare March 23, 2016 10:58
@@ -333,7 +333,7 @@ def notnull(obj):
pandas.isnull : boolean inverse of pandas.notnull
"""
res = isnull(obj)
if lib.isscalar(res):
if np.isscalar(res):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are reversing changes previously made.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thanks, fixed that.

@cldy
Copy link
Author

cldy commented Mar 23, 2016

Rebase done, still haven't figured out the locale error ...

@cldy cldy force-pushed the subclassing_fixes2 branch from 4f792c3 to f8e46ab Compare March 24, 2016 15:27
@cldy
Copy link
Author

cldy commented Mar 24, 2016

The locale error occurs only in my Travis, but the build seems to pass here. Also, I have squashed the commits.

@@ -130,6 +130,10 @@ def _constructor(self):

_constructor_sliced = DataFrame

_constructor_expanddim = _constructor
Copy link
Member

@sinhrks sinhrks Apr 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dupe, and is this tested somewhere? The definition looks inappropriate.

@sinhrks
Copy link
Member

sinhrks commented Apr 15, 2016

I think it's better to split the change to 2 parts which can be done with current _constructor_... mechanism and other methods which can't be covered.

If subclassing mechanism is being changed, internal.rst must be updated.

@cldy
Copy link
Author

cldy commented Jun 1, 2016

Sorry that this is taking so long ...

I am now working on it, but am currently having some problems with the (recent?) changes to sparse data types.

@cldy
Copy link
Author

cldy commented Jun 2, 2016

I have fixed the issues with Sparse data types, but I still get a number of these errors in Travis:

ERROR: pandas.io.tests.test_pickle.TestPickle.test_pickles('0.11.0',)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/miniconda/envs/pandas/lib/python3.4/site-packages/nose/case.py", line 382, in setUp
    try_run(self.inst, ('setup', 'setUp'))
  File "/home/travis/miniconda/envs/pandas/lib/python3.4/site-packages/nose/util.py", line 471, in try_run
    return func()
  File "/home/travis/build/cldy/pandas/pandas/io/tests/test_pickle.py", line 38, in setUp
    self.data = create_pickle_data()
  File "/home/travis/build/cldy/pandas/pandas/io/tests/generate_legacy_storage_files.py", line 154, in create_pickle_data
    if _loose_version < '0.14.1':
  File "/home/travis/miniconda/envs/pandas/lib/python3.4/distutils/version.py", line 58, in __lt__
    c = self._cmp(other)
  File "/home/travis/miniconda/envs/pandas/lib/python3.4/distutils/version.py", line 343, in _cmp
    if self.version < other.version:
TypeError: unorderable types: str() < int()

I don't quite understand how this is related to the changes I made. Any help would be very much appreciated.

@jreback
Copy link
Contributor

jreback commented Jun 2, 2016

make sure you rebased on master
Travis hit a limit with got clone depth the other day
I bumped it

@jreback
Copy link
Contributor

jreback commented Jun 2, 2016

git

@bruno-fs
Copy link

bruno-fs commented Jun 2, 2016

yay! finally! will the pypi package get this update soon? HUGE thanks @cldy @jreback ;)

result = value_counts(self, sort=sort, ascending=ascending,
normalize=normalize, bins=bins, dropna=dropna)
return result

if isinstance(self, Index):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use gt.ABCIndexClass (its already imported)

@jreback
Copy link
Contributor

jreback commented Sep 9, 2016

can you rebase / update?

@jreback
Copy link
Contributor

jreback commented Nov 22, 2016

@cldy closing; I would like to see this merged, but can we do this in pieces (e.g. smaller discrete changes). Certainly open an issue with a list of todo's that we can then check off though.

@jreback jreback closed this Nov 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Compat pandas objects compatability with Numpy or Python functions Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants