BUG: Fixed pd.unique on array of tuples
State: closed

Closes #16519

Labels:
name: Algos
description: Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff
name: Blocker
description: Blocking issue or pull request for an upcoming release

Comments:
I think you could back out this change from #16434

https://github.com/TomAugspurger/pandas/blob/35da5b9e60993b722760d52dc8dcc0a14129748e/pandas/core/algorithms.py#L391
I with agree @chris-b1 comment, yes that looks right.
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/16543?src=pr&el=h1) Report
> Merging [#16543](https://codecov.io/gh/pandas-dev/pandas/pull/16543?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/e60dc4cff2c6e8a2283fbb906faeb8cb01df37ff?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `100%`.

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

```diff
@@           Coverage Diff           @@
##           master   #16543   +/-   ##
=======================================
  Coverage   90.79%   90.79%           
=======================================
  Files         161      161           
  Lines       51063    51063           
=======================================
  Hits        46365    46365           
  Misses       4698     4698
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `88.63% <100%> (ø)` | :arrow_up: |
| #single | `40.15% <0%> (ø)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/16543?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/algorithms.py](https://codecov.io/gh/pandas-dev/pandas/pull/16543?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYWxnb3JpdGhtcy5weQ==) | `94.41% <100%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/16543?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/16543?src=pr&el=footer). Last update [e60dc4c...35da5b9](https://codecov.io/gh/pandas-dev/pandas/pull/16543?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/16543?src=pr&el=h1) Report
> Merging [#16543](https://codecov.io/gh/pandas-dev/pandas/pull/16543?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/e60dc4cff2c6e8a2283fbb906faeb8cb01df37ff?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `100%`.

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

```diff
@@           Coverage Diff           @@
##           master   #16543   +/-   ##
=======================================
  Coverage   90.79%   90.79%           
=======================================
  Files         161      161           
  Lines       51063    51063           
=======================================
  Hits        46365    46365           
  Misses       4698     4698
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `88.63% <100%> (ø)` | :arrow_up: |
| #single | `40.15% <0%> (ø)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/16543?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/algorithms.py](https://codecov.io/gh/pandas-dev/pandas/pull/16543?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYWxnb3JpdGhtcy5weQ==) | `94.41% <100%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/16543?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/16543?src=pr&el=footer). Last update [e60dc4c...35da5b9](https://codecov.io/gh/pandas-dev/pandas/pull/16543?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/16543?src=pr&el=h1) Report
> Merging [#16543](https://codecov.io/gh/pandas-dev/pandas/pull/16543?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/03d44f3dd0ffd55d7538b67466cf4d3899ceac27?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `100%`.

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

```diff
@@           Coverage Diff           @@
##           master   #16543   +/-   ##
=======================================
  Coverage   90.75%   90.75%           
=======================================
  Files         161      161           
  Lines       51074    51074           
=======================================
  Hits        46353    46353           
  Misses       4721     4721
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `88.59% <100%> (ø)` | :arrow_up: |
| #single | `40.16% <0%> (ø)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/16543?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/algorithms.py](https://codecov.io/gh/pandas-dev/pandas/pull/16543?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYWxnb3JpdGhtcy5weQ==) | `94.41% <100%> (ø)` | :arrow_up: |

------

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

> I think you could back out this change from #16434

The regression test from #16434 fails if I revert the change. The difference being

```python
(Pdb++) values  # this is with the fix reverted
array([[1, 'a']], dtype=object)
(Pdb++) lib.list_to_object_array(list([(1, 'a')]))  # this is the fix from 16434
array([(1, 'a')], dtype=object)
```

So an array of lists vs. an array of tuples. Is that correct?
you may just need to call
_ensure_arraylike there instead of the isinstance check
Using `_ensure_arraylike` failed on an empty array `pd.Series([1, 2]).isin([])` since it's a float instead of object dtype, so the hashing fails later on. I can handle that case if you want, or just leave the isinstance checks. Not sure which is cleaner really.
@TomAugspurger added a commit. should fix up I think.
@TomAugspurger looks this broke it. ok just revert my commit and merge your changes. This is a very touchy area. I we are doing the right things in the tests, but just tricky to get exactly right.
@TomAugspurger rebased to remove my commit.
@jreback are you able to restart appveyor jobs? One of the network tests failed on the first job.
thanks!