Named objs in asserts messages.
State: closed


### Feature
---

Ability to name objects being passed into `pandas.util.testing.assert_<type>_equal()` statements to allow for more helpful error messages Via the `obj` parameter.

#### Example:

```python
a = pd.Index([1, 2, 3, 4])
b = pd.Index([1, 2, 3, 5])

testing.assert_index_equal(a, b, obj=('Red', 'Blue'))
```
#### Output:
```diff
- AssertionError: Red and Blue are different
- 
- Red and Blue values are different (25.0 %)
- [Red]:  Int64Index([1, 2, 3, 4], dtype='int64')
- [Blue]: Int64Index([1, 2, 3, 5], dtype='int64')
```
---
However, messages & are still kept in tact.  For instance if I do a equal on two Dataframes with different values & pass in the names it will still append `.iloc[:, <idx>]` as shown:

#### Example:
```python
df1 = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]}, index=['a', 'b', 'c'])
df2 = pd.DataFrame({'A': [1, 2, 3], 'B': [6, 5, 4]}, index=['a', 'b', 'c'])

testing.assert_frame_equal(df1, df2, obj=('df1', 'df2'))
```
#### Output:
```diff
- AssertionError: df1.iloc[:, 1] and df2.iloc[:, 1] are different
- 
- df1.iloc[:, 1] and df2.iloc[:, 1] values are different (66.66667 %)
- [df1.iloc[:, 1]]: [4, 5, 6]
- [df2.iloc[:, 1]]: [6, 5, 4]
```
---
But, if this is undesired or unneeded, the default names, `('left', 'right')`, still persists.  As shown:

#### Example:
```python
testing.assert_index_equal(a, b)
```
#### Output:
```diff
- AssertionError: Index are different
- 
- Index values are different (25.0 %)
- [left]:  Int64Index([1, 2, 3, 4], dtype='int64')
- [right]: Int64Index([1, 2, 3, 5], dtype='int64')
```

It should be noted where were a _few_ cases where I had to change the default messages due to some hard-coded messages, I've updated the tests for those specific cases.  **but** if for some reason someone has something that relies on those messages being exactly what they were they will now break.

---
Checklist for other PRs:

- [x] closes #xxxx (N/A)
- [x] tests added / passed*
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [ ] whatsnew entry

\* There were 4 unrelated tests that were failing on upstream/master & those 4 still fail, but all the tests related to the files I edit still pass.

Labels:
name: Testing
description: pandas testing functions or related to the test suite

Comments:
I'm curious: what's the motivation for this?

Internal to pandas, we always use `result, expected` for the ordering, so that should be understood.

Are you using this elsewhere?
@TomAugspurger, for a different project I had to write test cases that .csv files & .json files matched but since I couldn't pass in names when the errors printed out it wasn't immediately easy to tell which file was wrong so I ended up having to Jerry rig something like this.  I figured someone else might also find it useful as well.


Fair enough, just wanted to make sure since this seems like a fairly
pervasive change.

On Mon, Mar 19, 2018 at 8:07 AM, Aaron N. Brock <notifications@github.com>
wrote:

> @TomAugspurger <https://github.com/tomaugspurger>, for a different
> project I had to write test cases that .cvs files & .json files matched but
> since I couldn't pass in names when the errors printed out it wasn't
> immediately easy to tell which file was wrong so I ended up having to Jerry
> rig something like this. I figured someone else might also find it useful
> as well.
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/pandas-dev/pandas/pull/20403#issuecomment-374204981>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/ABQHIgRsi1LfkxMmOgACmJaJkb_kd69fks5tf62LgaJpZM4SvT22>
> .
>

At it's core, it's just changing "obj" to optionally be a list/tuple then adding some extra formatting at the end, but to do that requires to change each method that takes in obj to support it, so it's more of a refactoring change than a wide spread functionality change.

That being said, even now I do think the assertion messages could still be better & have more options.  For instance, it would be nice if instead of printing out _all_ of `left` & `right` there was an option to print out only the places where they are different.  (if, for instance, `left` & `right` are 100+ elements printing out the entire lists is kinda unhelpful).

Also, it seems a bit redundant to both print out `df1.iloc[:, 1] and df2.iloc[:, 1] are different` and `df1.iloc[:, 1] and df2.iloc[:, 1] values are different (66.66667 %)` it the same message since from the second statement the first is implied.

But those are projects for another weekend.
I understand where you are going with this. but it adds quite a bit of complexity. ok with a simpler soln.