Subclassing improvements
State: closed

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.


Labels:
name: Indexing
description: Related to indexing on series/frames, not to indexes themselves
name: Compat
description: pandas objects compatability with Numpy or Python functions

Comments:
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?

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

pls rebase/update

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

## [Current coverage](https://codecov.io/gh/pydata/pandas/pull/12308?src=pr) is **88.69%**

> Merging [#12308](https://codecov.io/gh/pydata/pandas/pull/12308?src=pr) into [master](https://codecov.io/gh/pydata/pandas/branch/master?src=pr) will increase coverage by **4.46%**

``` diff
@@             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](https://codecov.io?src=pr). Last updated by [2e3c82e...297ffe0](https://codecov.io/gh/pydata/pandas/compare/2e3c82e81bf00af157268a842a270a6181fcb168...297ffe03bdc57d0cb8c7763616c215cdbc9fd644)

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.

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

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

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

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.

pls rebase this

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

But I am not really changing the mechanism, just replacing hard-coded return types by constructor properties.

It does change. Otherwise, you can remove `Series._constructor_sliced` and `Panel._constructor_expanddim`.
- http://pandas.pydata.org/pandas-docs/stable/internals.html#override-constructor-properties

Sorry, you are right. I introduced the Series._constructor_sliced to avoid type checking (in case of functions that take both DataFrame and Series as input but always return Series), but that is really a little ugly and I should probably change it. (Same for the Panel._constructor_exanddim.)

@cldy if you'd like to update.

can you rebase / update?

@cldy can you rebase / update

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.

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.

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

git

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

can you rebase / update?

@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.