BUG-24915 fix unhashble Series.name in df aggregation
State: closed

- [x] closes #24915
- [ ] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [ ] whatsnew entry

Before creating a pd.Series and pass {name} as argument, check if {name} is hashable. If not use default None.

Labels:
name: Reshaping
description: Concat, Merge/Join, Stack/Unstack, Explode

Comments:
@yaoquanye @daisysu0310
1. not sure about what tests to add

@youhealthy and I are the same person
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/24920?src=pr&el=h1) Report
> Merging [#24920](https://codecov.io/gh/pandas-dev/pandas/pull/24920?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/539c54f30736b4163b70f1ba903aee7a4243ab1f?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `100%`.

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

```diff
@@            Coverage Diff             @@
##           master   #24920      +/-   ##
==========================================
+ Coverage   92.38%   92.38%   +<.01%     
==========================================
  Files         166      166              
  Lines       52404    52406       +2     
==========================================
+ Hits        48412    48414       +2     
  Misses       3992     3992
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.8% <100%> (ø)` | :arrow_up: |
| #single | `42.9% <0%> (-0.01%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/24920?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/base.py](https://codecov.io/gh/pandas-dev/pandas/pull/24920/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYmFzZS5weQ==) | `97.76% <100%> (+0.01%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/24920?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/24920?src=pr&el=footer). Last update [539c54f...b270371](https://codecov.io/gh/pandas-dev/pandas/pull/24920?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/24920?src=pr&el=h1) Report
> Merging [#24920](https://codecov.io/gh/pandas-dev/pandas/pull/24920?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/539c54f30736b4163b70f1ba903aee7a4243ab1f?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `100%`.

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

```diff
@@            Coverage Diff             @@
##           master   #24920      +/-   ##
==========================================
+ Coverage   92.38%   92.38%   +<.01%     
==========================================
  Files         166      166              
  Lines       52404    52406       +2     
==========================================
+ Hits        48412    48414       +2     
  Misses       3992     3992
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.8% <100%> (ø)` | :arrow_up: |
| #single | `42.9% <0%> (-0.01%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/24920?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/base.py](https://codecov.io/gh/pandas-dev/pandas/pull/24920/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYmFzZS5weQ==) | `97.76% <100%> (+0.01%)` | :arrow_up: |

------

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

@jreback I agree with you. You can refer to #24915 for the problem.

There are 2 ways that I have in mind to fix this:
1. This PR.
2. Make change to how __getattr__ works.

For 2. What I looked at is

```python
#pandas.core.generic.py
if (name in self._internal_names_set or name in self._metadata or
    name in self._accessors):
        return object.__getattribute__(self, name)
else:
    if self._info_axis._can_hold_identifiers_and_holds_name(name):
        return self[name]
    return object.__getattribute__(self, name)
```
`getattr(self, "name")` will go to else clause, and if "name" is a column, it will return in if clause. But df.name is really an attribute rather not a column name. It should skip that "if" in "else" and goes to object.__getattribute__().

How do you propose to change? @jreback 



@jreback any idea?
@lofoyet first thing you need here is a test. Then step thru it until you get to the source of the error, see if you patch fixes.

I would rather shy away from changing the way getattr works. Also I am not sure your change is the right way.
Closing as stale. @lofoyet ping if you'd like to continue though as mentioned above this needs a test first and foremost