DEPR: Deprecate convert parameter in take
State: closed

xref #16948.

The parameter is not respected, nor is it a parameter in many 'take' implementations.

cc @jorisvandenbossche 

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

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

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

```diff
@@            Coverage Diff             @@
##           master   #17352      +/-   ##
==========================================
- Coverage   91.03%   91.02%   -0.02%     
==========================================
  Files         162      162              
  Lines       49567    49577      +10     
==========================================
+ Hits        45125    45126       +1     
- Misses       4442     4451       +9
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `88.8% <86.66%> (ø)` | :arrow_up: |
| #single | `40.23% <23.33%> (-0.07%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/17352?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/groupby.py](https://codecov.io/gh/pandas-dev/pandas/pull/17352?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ3JvdXBieS5weQ==) | `92.21% <100%> (ø)` | :arrow_up: |
| [pandas/core/sparse/series.py](https://codecov.io/gh/pandas-dev/pandas/pull/17352?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvc3BhcnNlL3Nlcmllcy5weQ==) | `95.13% <100%> (+0.04%)` | :arrow_up: |
| [pandas/core/series.py](https://codecov.io/gh/pandas-dev/pandas/pull/17352?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvc2VyaWVzLnB5) | `95.01% <100%> (ø)` | :arrow_up: |
| [pandas/core/indexing.py](https://codecov.io/gh/pandas-dev/pandas/pull/17352?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhpbmcucHk=) | `93.94% <75%> (ø)` | :arrow_up: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/17352?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.72% <75%> (-0.1%)` | :arrow_down: |
| [pandas/core/generic.py](https://codecov.io/gh/pandas-dev/pandas/pull/17352?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ2VuZXJpYy5weQ==) | `92% <87.5%> (+0.01%)` | :arrow_up: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/17352?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/17352?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/17352?src=pr&el=footer). Last update [473a7f3...4471360](https://codecov.io/gh/pandas-dev/pandas/pull/17352?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/17352?src=pr&el=h1) Report
> Merging [#17352](https://codecov.io/gh/pandas-dev/pandas/pull/17352?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/030e374940a93b7920c0c2ac5c950668564c3703?src=pr&el=desc) will **decrease** coverage by `0.01%`.
> The diff coverage is `92.45%`.

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

```diff
@@            Coverage Diff             @@
##           master   #17352      +/-   ##
==========================================
- Coverage   91.27%   91.25%   -0.02%     
==========================================
  Files         163      163              
  Lines       49766    49785      +19     
==========================================
+ Hits        45422    45433      +11     
- Misses       4344     4352       +8
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `89.05% <92.45%> (ø)` | :arrow_up: |
| #single | `40.34% <60.37%> (-0.05%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/17352?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/sparse/series.py](https://codecov.io/gh/pandas-dev/pandas/pull/17352?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvc3BhcnNlL3Nlcmllcy5weQ==) | `95.15% <100%> (+0.05%)` | :arrow_up: |
| [pandas/core/series.py](https://codecov.io/gh/pandas-dev/pandas/pull/17352?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvc2VyaWVzLnB5) | `95.04% <100%> (+0.1%)` | :arrow_up: |
| [pandas/core/groupby.py](https://codecov.io/gh/pandas-dev/pandas/pull/17352?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ3JvdXBieS5weQ==) | `92.23% <100%> (ø)` | :arrow_up: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/17352?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.73% <75%> (-0.1%)` | :arrow_down: |
| [pandas/core/indexing.py](https://codecov.io/gh/pandas-dev/pandas/pull/17352?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhpbmcucHk=) | `93.94% <75%> (ø)` | :arrow_up: |
| [pandas/core/generic.py](https://codecov.io/gh/pandas-dev/pandas/pull/17352?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ2VuZXJpYy5weQ==) | `92.12% <96%> (+0.04%)` | :arrow_up: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/17352?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |

------

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

So I originally added this because I wanted the ability to a) convert neg to positive, and b) bounds check; these are not the default because of perf (IOW internally we often *know* that we don't need either of these things, but from a public perspetive you do need this).

 These shouldn't have been on the public NDFrame though (so good to remove). So the question is, do we need a ``._take()`` to do these things? (and ``.take()`` would just be a wrapper)?
I'd be in favor of a `_take` with options to be unsafe.  It's not like boundschecking is that expensive, but it's such a core operation I hate to give up any performance.
I suppose that in the name of performance, that's fair.  I think I would just need to implement this solely for `DataFrame` and `Series` right?
Yes, that's correct.  `BlockManager` and `SingleBlockManager` will need to keep their `take` implementation, but I would keep it unprefixed since they are already internal.
@chris-b1 : Sorry, somehow your answer only confused me more.  Yes or no, do I need to implement `_take` for just `Series` and `DataFrame` ?
yes

On Tue, Aug 29, 2017 at 3:37 PM, gfyoung <notifications@github.com> wrote:

> @chris-b1 <https://github.com/chris-b1> : Sorry, somehow your answer only
> confused me more. Yes or no, do I need to implement _take for just Series
> and DataFrame ?
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/pandas-dev/pandas/pull/17352#issuecomment-325796434>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AB1b_Duk4u1gGVVH0bjyBu6xvA6OgmHvks5sdHaUgaJpZM4PD6BQ>
> .
>

@chris-b1 : Alright, here goes.  Let's see what CI has to say about my implementation.
@chris-b1 @jreback : Successfully implemented `_take` with all green.  PTAL. 
so this still needs to change virtually all uses of ``.take()`` -> ``._take()``. We want to limit the exposure to user-facing ``.take()`` in any code that is not explicitly user facing.
https://travis-ci.org/pandas-dev/pandas/jobs/279023089

@jreback : Not sure why doing this conversion to `_.take()` is causing test failures.
> ok, not really sure why it shoulnt' work. its almost the same code

Well, the test results speak for themselves.  I'm perfectly fine with simplifying the code, but tests are breaking + the changes are starting to stray away from the original intent.
@jreback : I've done all of the converting (without breaking tests).  PTAL.
thanks @gfyoung !
> pandas/tests/sparse/test_series.py::TestSparseSeries::()::test_numpy_take
  /home/travis/miniconda3/envs/pandas/lib/python3.5/site-packages/numpy/core/fromnumeric.py:123: FutureWarning: The 'convert' parameter is deprecated and will be removed in a future version.
    return take(indices, axis, out, mode)

coming up on the 3.5 build of master

seems we r not suppressing somewhere (or prob needs to change to use _take maybe)

can u take care of @gfyoung 
@jreback : The cause of the warning is that an older version of `numpy` passes in `None` to `convert` by default when calling `np.take` (see <a href="https://github.com/numpy/numpy/blob/v1.11.3/numpy/core/fromnumeric.py#L123">here</a>).  

Thus, this is a compatibility issue, as it disappears in later versions of `numpy` (I actually worked on fixing `fromnumeric` compatibility issues at some point).

I'll put a check in the test to expect that warning for older versions of `numpy`, as checking `if not convert` is pretty idiomatic, and I wouldn't want to change it just because an older version of `numpy` is issuing a warning when we call `.take()` in a non-recommended way.