DEPR: deprecate .asobject property
State: closed

This PR supersedes #18477. 
closes #18237
 
- [ x] xref #18262
- [x ] tests added / passed
- [ x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [ x] whatsnew entry

Deprecate ``Series.asobject`` and ``DatetimeIndexOpsMixin.asobject`` as per discussion in #18262. ``DatetimeIndexOpsMixin`` is a mixin for ``DatetimeIndex``, ``PeriodIndex`` and ``TimeDeltaIndex``, so all the ``.asobject`` property will be deprecated all those classes.

Internal references to ``asobject`` have been cleaned up, so a eventual removal will be easy when that time comes.

Labels:
name: Deprecate
description: Functionality to remove in pandas

Comments:
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/18572?src=pr&el=h1) Report
> Merging [#18572](https://codecov.io/gh/pandas-dev/pandas/pull/18572?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/7627ccaf9442f4101afda69b6077e7f035e23543?src=pr&el=desc) will **decrease** coverage by `0.01%`.
> The diff coverage is `93.54%`.

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

```diff
@@            Coverage Diff             @@
##           master   #18572      +/-   ##
==========================================
- Coverage   91.35%   91.33%   -0.02%     
==========================================
  Files         164      164              
  Lines       49802    49806       +4     
==========================================
- Hits        45496    45490       -6     
- Misses       4306     4316      +10
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `89.13% <93.54%> (-0.01%)` | :arrow_down: |
| #single | `40.81% <32.25%> (-0.07%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/18572?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/ops.py](https://codecov.io/gh/pandas-dev/pandas/pull/18572?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvb3BzLnB5) | `91.77% <ø> (ø)` | :arrow_up: |
| [pandas/plotting/\_converter.py](https://codecov.io/gh/pandas-dev/pandas/pull/18572?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL19jb252ZXJ0ZXIucHk=) | `65.25% <0%> (ø)` | :arrow_up: |
| [pandas/core/indexes/period.py](https://codecov.io/gh/pandas-dev/pandas/pull/18572?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9wZXJpb2QucHk=) | `92.94% <100%> (ø)` | :arrow_up: |
| [pandas/io/formats/format.py](https://codecov.io/gh/pandas-dev/pandas/pull/18572?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvZm9ybWF0LnB5) | `96.01% <100%> (ø)` | :arrow_up: |
| [pandas/core/internals.py](https://codecov.io/gh/pandas-dev/pandas/pull/18572?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW50ZXJuYWxzLnB5) | `94.44% <100%> (-0.04%)` | :arrow_down: |
| [pandas/core/indexing.py](https://codecov.io/gh/pandas-dev/pandas/pull/18572?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhpbmcucHk=) | `92.8% <100%> (ø)` | :arrow_up: |
| [pandas/core/indexes/datetimelike.py](https://codecov.io/gh/pandas-dev/pandas/pull/18572?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9kYXRldGltZWxpa2UucHk=) | `96.93% <100%> (+0.02%)` | :arrow_up: |
| [pandas/core/indexes/datetimes.py](https://codecov.io/gh/pandas-dev/pandas/pull/18572?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9kYXRldGltZXMucHk=) | `95.71% <100%> (ø)` | :arrow_up: |
| [pandas/core/algorithms.py](https://codecov.io/gh/pandas-dev/pandas/pull/18572?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYWxnb3JpdGhtcy5weQ==) | `94.14% <100%> (ø)` | :arrow_up: |
| [pandas/core/dtypes/concat.py](https://codecov.io/gh/pandas-dev/pandas/pull/18572?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZHR5cGVzL2NvbmNhdC5weQ==) | `99.13% <100%> (ø)` | :arrow_up: |
| ... and [6 more](https://codecov.io/gh/pandas-dev/pandas/pull/18572?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/18572?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/18572?src=pr&el=footer). Last update [7627cca...4cb8776](https://codecov.io/gh/pandas-dev/pandas/pull/18572?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/18572?src=pr&el=h1) Report
> Merging [#18572](https://codecov.io/gh/pandas-dev/pandas/pull/18572?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/6e56195fcb021e7c53301722804087ef2a83bc39?src=pr&el=desc) will **decrease** coverage by `0.04%`.
> The diff coverage is `94.28%`.

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

```diff
@@            Coverage Diff             @@
##           master   #18572      +/-   ##
==========================================
- Coverage   91.46%   91.42%   -0.05%     
==========================================
  Files         157      157              
  Lines       51449    51454       +5     
==========================================
- Hits        47060    47043      -17     
- Misses       4389     4411      +22
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `89.29% <94.28%> (-0.03%)` | :arrow_down: |
| #single | `40.6% <37.14%> (-0.11%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/18572?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/ops.py](https://codecov.io/gh/pandas-dev/pandas/pull/18572/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvb3BzLnB5) | `91.77% <ø> (ø)` | :arrow_up: |
| [pandas/plotting/\_converter.py](https://codecov.io/gh/pandas-dev/pandas/pull/18572/diff?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL19jb252ZXJ0ZXIucHk=) | `63.44% <0%> (-1.82%)` | :arrow_down: |
| [pandas/io/formats/format.py](https://codecov.io/gh/pandas-dev/pandas/pull/18572/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvZm9ybWF0LnB5) | `96.01% <100%> (ø)` | :arrow_up: |
| [pandas/core/indexing.py](https://codecov.io/gh/pandas-dev/pandas/pull/18572/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhpbmcucHk=) | `92.81% <100%> (ø)` | :arrow_up: |
| [pandas/core/indexes/period.py](https://codecov.io/gh/pandas-dev/pandas/pull/18572/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9wZXJpb2QucHk=) | `92.94% <100%> (ø)` | :arrow_up: |
| [pandas/core/internals.py](https://codecov.io/gh/pandas-dev/pandas/pull/18572/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW50ZXJuYWxzLnB5) | `94.44% <100%> (-0.04%)` | :arrow_down: |
| [pandas/core/indexes/timedeltas.py](https://codecov.io/gh/pandas-dev/pandas/pull/18572/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy90aW1lZGVsdGFzLnB5) | `91.21% <100%> (ø)` | :arrow_up: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/18572/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.81% <100%> (-0.1%)` | :arrow_down: |
| [pandas/core/accessor.py](https://codecov.io/gh/pandas-dev/pandas/pull/18572/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYWNjZXNzb3IucHk=) | `93.75% <100%> (ø)` | :arrow_up: |
| [pandas/core/indexes/datetimes.py](https://codecov.io/gh/pandas-dev/pandas/pull/18572/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9kYXRldGltZXMucHk=) | `95.69% <100%> (ø)` | :arrow_up: |
| ... and [8 more](https://codecov.io/gh/pandas-dev/pandas/pull/18572/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/18572?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/18572?src=pr&el=footer). Last update [6e56195...d61f411](https://codecov.io/gh/pandas-dev/pandas/pull/18572?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

all is green, I think the failure on appveyoyor is unrelated to the PR.

Some points:
* We discussed that ``asobject`` should just return ``self.astype(object)``. It turns out that the relevant versions of ``index .astype`` call ``.asobject`` themselves, so to avoid circular calls, I've kept a new internal ``._asobject``. This also avoids code duplication in the various ``astype`` methods. All internal calls use ``.astype(object)`` and not ``.asobject``. So ``._asobject`` is only used by ``astype``.
* The return values of the various ``Index.asobject`` is ``astype(object)``, but for ``Series.asobject`` the return value is ``astype(object).values``. so there's a need to differentiate between the two.

In general: please don't open new PRs, but just update the original one.
PR updated and all is green now.

Wrt. ``._asobject`` I felt that having a common internal method was cleaner, but its not something I feel strongly about. But I've kept it as is.

Changing it later would be trivial, as its only called from three places. so IMO its not a very large technical debt, if it even is one.
@topper-123 

ok, do this

move what you are calling ``_asobject()`` and call it ``_box_values_as_index()`` and put it underneath ``_box_values()``. eliminate all calls to it as possible, ideally you would only have the 1 remaining one in the ``def astype()`` in each of the datetimelike subclasses.
Updated.

``asobject`` is a property. I therefore have updated ``_deprecations`` to include it. Otherwise the warning get printed in ipython everytime we tab complete.
All green. Please verify if last change is ok.
All green.
Hello @topper-123! Thanks for updating the PR.





























































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

##### Comment last updated on December 04, 2017 at 10:00 Hours UTC
Thanks a lot @topper-123 !