Add base test for extensionarray setitem #23300
State: closed

- [x] closes #23300 
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry


Labels:
name: Testing
description: pandas testing functions or related to the test suite
name: ExtensionArray
description: Extending pandas with custom dtypes or arrays.

Comments:
Hello @charlesdong1991! Thanks for submitting the PR.

 - There are no PEP8 issues in the file [`pandas/conftest.py`](https://github.com/charlesdong1991/pandas/blob/ddce1fe4a3a5895aabf38481292ec36198c1a3e2/pandas/conftest.py) !

 - There are no PEP8 issues in the file [`pandas/tests/extension/base/setitem.py`](https://github.com/charlesdong1991/pandas/blob/ddce1fe4a3a5895aabf38481292ec36198c1a3e2/pandas/tests/extension/base/setitem.py) !


Looks like the fixture name `box` is already taken

```
    raise ValueError("duplicate %r" % (arg,))
E   ValueError: duplicate 'box'
--------------------- generated xml file: /tmp/single.xml ----------------------
!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!!
============ 7 skipped, 35608 deselected, 1 error in 35.79 seconds =============

```

You could rename it to `box_in_series` perhaps.


FYI, you may want to run the tests locally for a faster feedback loop. `pytest pandas/tests/extension` or even just `pytest pandas/tests/extension/decimal`.
looks good.

@TomAugspurger IIRC on Sparse you were showing a warning on setitem (for perf)? is this tested ?
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/23304?src=pr&el=h1) Report
> :exclamation: No coverage uploaded for pull request base (`master@4a11eac`). [Click here to learn what that means](https://docs.codecov.io/docs/error-reference#section-missing-base-commit).
> The diff coverage is `n/a`.

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

```diff
@@            Coverage Diff            @@
##             master   #23304   +/-   ##
=========================================
  Coverage          ?   92.23%           
=========================================
  Files             ?      169           
  Lines             ?    50925           
  Branches          ?        0           
=========================================
  Hits              ?    46969           
  Misses            ?     3956           
  Partials          ?        0
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.65% <ø> (?)` | |
| #single | `42.28% <ø> (?)` | |


------

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

SparseArray doesn't implement `__setitem__` (old one didn't either, though there's an open PR to implement it).
Thanks @charlesdong1991!
ah, sorry, i see, thanks for pointing it out... can PR be reopened?

Tom Augspurger <notifications@github.com> 于2018年10月26日周五 下午1:11写道：

> *@TomAugspurger* commented on this pull request.
> ------------------------------
>
> In pandas/tests/extension/base/setitem.py
> <https://github.com/pandas-dev/pandas/pull/23304#discussion_r228489475>:
>
> > @@ -32,22 +34,25 @@ def test_setitem_sequence_mismatched_length_raises(self, data, as_array):
>          xpr = 'cannot set using a {} indexer with a different length'
>          with tm.assert_raises_regex(ValueError, xpr.format('list-like')):
>              ser[[0, 1]] = value
> +            assert ser._values[[0, 1]] == value
>
> Ah, sorry I missed that.
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/pandas-dev/pandas/pull/23304#discussion_r228489475>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AI1yOGQ5uaG34l6w7Z-FoUOuyL5dF4yHks5uou3ggaJpZM4X2dmH>
> .
>

No worries. I made a new PR to fix it.

On Fri, Oct 26, 2018 at 7:11 AM Kaiqi Dong <notifications@github.com> wrote:

> ah, sorry, i see, thanks for pointing it out... can PR be reopened?
>
> Tom Augspurger <notifications@github.com> 于2018年10月26日周五 下午1:11写道：
>
> > *@TomAugspurger* commented on this pull request.
> > ------------------------------
> >
> > In pandas/tests/extension/base/setitem.py
> > <https://github.com/pandas-dev/pandas/pull/23304#discussion_r228489475>:
> >
> > > @@ -32,22 +34,25 @@ def
> test_setitem_sequence_mismatched_length_raises(self, data, as_array):
> > xpr = 'cannot set using a {} indexer with a different length'
> > with tm.assert_raises_regex(ValueError, xpr.format('list-like')):
> > ser[[0, 1]] = value
> > + assert ser._values[[0, 1]] == value
> >
> > Ah, sorry I missed that.
> >
> > —
> > You are receiving this because you were mentioned.
> > Reply to this email directly, view it on GitHub
> > <https://github.com/pandas-dev/pandas/pull/23304#discussion_r228489475>,
> > or mute the thread
> > <
> https://github.com/notifications/unsubscribe-auth/AI1yOGQ5uaG34l6w7Z-FoUOuyL5dF4yHks5uou3ggaJpZM4X2dmH
> >
> > .
> >
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/pandas-dev/pandas/pull/23304#issuecomment-433386882>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/ABQHIuddzCfKW5Ial4NgWdsKkwH38W2Vks5uovvxgaJpZM4X2dmH>
> .
>

thanks! and appreciate a lot for your patience, guidance and kindness.
it's my first time to try to contribute to such big open source project,
and still feel excited and looking forward to doing more...
wish i could make less trouble for all of you in next PR... ^^

Tom Augspurger <notifications@github.com> 于2018年10月26日周五 下午2:13写道：

> No worries. I made a new PR to fix it.
>
> On Fri, Oct 26, 2018 at 7:11 AM Kaiqi Dong <notifications@github.com>
> wrote:
>
> > ah, sorry, i see, thanks for pointing it out... can PR be reopened?
> >
> > Tom Augspurger <notifications@github.com> 于2018年10月26日周五 下午1:11写道：
> >
> > > *@TomAugspurger* commented on this pull request.
> > > ------------------------------
> > >
> > > In pandas/tests/extension/base/setitem.py
> > > <https://github.com/pandas-dev/pandas/pull/23304#discussion_r228489475
> >:
> > >
> > > > @@ -32,22 +34,25 @@ def
> > test_setitem_sequence_mismatched_length_raises(self, data, as_array):
> > > xpr = 'cannot set using a {} indexer with a different length'
> > > with tm.assert_raises_regex(ValueError, xpr.format('list-like')):
> > > ser[[0, 1]] = value
> > > + assert ser._values[[0, 1]] == value
> > >
> > > Ah, sorry I missed that.
> > >
> > > —
> > > You are receiving this because you were mentioned.
> > > Reply to this email directly, view it on GitHub
> > > <https://github.com/pandas-dev/pandas/pull/23304#discussion_r228489475
> >,
> > > or mute the thread
> > > <
> >
> https://github.com/notifications/unsubscribe-auth/AI1yOGQ5uaG34l6w7Z-FoUOuyL5dF4yHks5uou3ggaJpZM4X2dmH
> > >
> > > .
> > >
> >
> > —
> > You are receiving this because you were mentioned.
> > Reply to this email directly, view it on GitHub
> > <https://github.com/pandas-dev/pandas/pull/23304#issuecomment-433386882
> >,
> > or mute the thread
> > <
> https://github.com/notifications/unsubscribe-auth/ABQHIuddzCfKW5Ial4NgWdsKkwH38W2Vks5uovvxgaJpZM4X2dmH
> >
> > .
> >
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/pandas-dev/pandas/pull/23304#issuecomment-433387235>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AI1yOIQjwLFzgvsCtCJPlXGfAaEHXTspks5uovxYgaJpZM4X2dmH>
> .
>