Keep subclassing in apply
State: closed

When generating new objects on apply, it calls `self.obj._constructor` and `self.obj._constructior_sliced` instead of:  `DataFrame` and `Series`; keeping subclassing.

- [x] closes #19822
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] keeps subclass inside `DataFrame.apply`


Labels:
name: Reshaping
description: Concat, Merge/Join, Stack/Unstack, Explode
name: Compat
description: pandas objects compatability with Numpy or Python functions

Comments:
Hello @jaumebonet! Thanks for updating the PR.





Cheers ! There are no PEP8 issues in this Pull Request. :beers: 

##### Comment last updated on February 23, 2018 at 08:49 Hours UTC
Thanks - needs some tests, and it looks like it broke something for sparse, otherwise your approach seems reasonable at a glance.
Hi @chris-b1,
Thanks!
Yes, I'm trying to pinpoint what exactly has changed... Clearly it has to do with the fact that now it returns `SparseSeries` instead of `Series`, but I'm not familiar with `SparseSeries`, so I'm not sure what difference does that make.
can you add some tests in pandas/tests/frame/test_sub_class (and for Series as well)
also pls add a release note, other enhancements section is ok
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/19823?src=pr&el=h1) Report
> Merging [#19823](https://codecov.io/gh/pandas-dev/pandas/pull/19823?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/8768876a51a3dfa0625bab6925caca8b3e9fcceb?src=pr&el=desc) will **increase** coverage by `0.02%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/19823/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/19823?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #19823      +/-   ##
==========================================
+ Coverage   91.58%   91.61%   +0.02%     
==========================================
  Files         150      150              
  Lines       48908    48906       -2     
==========================================
+ Hits        44792    44804      +12     
+ Misses       4116     4102      -14
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `89.98% <100%> (+0.02%)` | :arrow_up: |
| #single | `41.78% <0%> (ø)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/19823?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/apply.py](https://codecov.io/gh/pandas-dev/pandas/pull/19823/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXBwbHkucHk=) | `96.74% <100%> (-0.04%)` | :arrow_down: |
| [pandas/util/testing.py](https://codecov.io/gh/pandas-dev/pandas/pull/19823/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvdGVzdGluZy5weQ==) | `83.85% <0%> (+0.2%)` | :arrow_up: |
| [pandas/plotting/\_converter.py](https://codecov.io/gh/pandas-dev/pandas/pull/19823/diff?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL19jb252ZXJ0ZXIucHk=) | `66.95% <0%> (+1.73%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/19823?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/19823?src=pr&el=footer). Last update [8768876...87f2c5c](https://codecov.io/gh/pandas-dev/pandas/pull/19823?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

Hi @jreback,
I've added a test to check if subclass of `Series` are kept when using apply on `DataFrame`.
`Series` have they own apply function, so the changes do not affect how `Series.apply` behave. 

As per your suggestion, I also added a bullet point in the _other enhancement_ section.
thanks!