BUG: Fix Grouper with a datetime key in conjunction with another key
State: closed

- [x] closes #51158 
- [x] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature
- [x] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit).
- [x] Added [type annotations](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#type-hints) to new arguments/methods/functions.
- [x] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature.


# Description of the bug

The crux of the issue was in `BaseGrouper::groups`:

```
to_groupby = zip(*(ping.grouping_vector for ping in self.groupings))
```

We are going to iterate over `to_groupby`, which is a `zip` of `ping.grouping_vector`.

`groupings` are populated in `get_grouper`, below is an excerpt of relevant code that we executed in case of grouping by date:

```python
        # Taking this branch because grouping_vector is `TimeGrouper`
        elif isinstance(grouping_vector, Grouper):
            newgrouper, newobj = grouping_vector._get_grouper(self.obj, validate=False)
            # newgrouper is BinGrouper after the line above
            if isinstance(newgrouper, ops.BinGrouper):
                grouping_vector = newgrouper
```
after this, `Grouping::grouping_vector` is `BinGrouper`, and **this is what `zip()` will try to iterate over**.

Before the fix, when we were iterating over `BinGrouper`, its base class `__iter__` was used, which was using `self.indices`, which was:
```
defaultdict(<class 'list'>, {Timestamp('2000-01-01 00:00:00'): [0, 1, 2], 
                             Timestamp('2000-01-02 00:00:00'): [3, 4, 5]})
```

When you iterate over a dictionary in Python, you iterate over the **keys**, and more importantly we have **only two of them here**. Second `Grouping` has `array` in its grouping vector consisting of **6 elements**:

```
['a' 'b' 'a' 'b' 'a' 'b']
```

so, the `zip()` function just truncated it.


# Fix

By adding `__iter__` in `BinGrouper`, the `zip()` function now iterate over the elements from `self.groupings[0].grouping_vector`, which is, in our case:

```
DatetimeIndex(['2000-01-01', '2000-01-01', '2000-01-01', '2000-01-02',
               '2000-01-02', '2000-01-02'],
              dtype='datetime64[ns]', name='b', freq=None)
```

Labels:
name: Bug
name: Groupby

Comments:
@jbrockmendel @rhshadrach Can you please have a look and/or advise? Thanks.
@jbrockmendel I fixed all your comments. Can you please review the PR? Thanks.
@jbrockmendel I am wondering whether you had time to have a look the PR? If not, should I add someone else to the PR to review it?

Also, am I missing something or the tests a quite flaky?
For example, right now NumPy is failing with this:

```
Fatal Python error: Segmentation fault
```
Please be patient, there are a lot of PRs to review.

The segfault is unrelated and is affecting all PRs at the moment.  You can ignore it.
@jbrockmendel have you had time to have a look?
@jbrockmendel Any news, please?
Thanks @juleek!