Calculate normalized freqs in value_counts correctly when bins is not None
State: closed

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


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

Comments:
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/26923?src=pr&el=h1) Report
> :exclamation: No coverage uploaded for pull request base (`master@df3d9b2`). [Click here to learn what that means](https://docs.codecov.io/docs/error-reference#section-missing-base-commit).
> The diff coverage is `100%`.

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

```diff
@@            Coverage Diff            @@
##             master   #26923   +/-   ##
=========================================
  Coverage          ?   91.86%           
=========================================
  Files             ?      180           
  Lines             ?    50745           
  Branches          ?        0           
=========================================
  Hits              ?    46619           
  Misses            ?     4126           
  Partials          ?        0
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.46% <100%> (?)` | |
| #single | `41.12% <0%> (?)` | |

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

------

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

Hello @krsnik93! Thanks for updating this PR. We checked the lines you've touched for [PEP 8](https://www.python.org/dev/peps/pep-0008) issues, and found:





There are currently no PEP 8 issues detected in this Pull Request. Cheers! :beers: 

##### Comment last updated at 2019-09-09 07:34:18 UTC
@krsnik93 can you merge master & add a whatsnew note (bug fix in reshaping is ok). ping on green.
I have a failing test in `tests/groupby/test_value_counts.py`. The test compares `Series.value_counts` against `SeriesGroupBy.value_counts`. For this issue, I modified `Series.value_counts` and I think the change is correct. However, I think `SeriesGroupBy.value_counts` should change as well. This is the troubling bit:

https://github.com/pandas-dev/pandas/blob/c275dbfcee0fa9644fa2718ad76fd91ca056069b/pandas/core/groupby/generic.py#L1261-L1275

For some reason, it takes by-group counts of unbinned data (either NaN values or outside of bin breaks) and resets those counts to 0 (last line). I do not understand why is this done, but the whole method is kind hard to read and I am not able to make the required changes.
cc @jschendel if you have time to take a look at https://github.com/pandas-dev/pandas/pull/26923#issuecomment-504328194.
@krsnik93 can you merge master and fix up merge conflicts?
Closing as this looks stale, but @krsnik93 please ping if you'd like to continue and can open back up