Fix issue #47101
Reapplies PR #59492

See https://github.com/pandas-dev/pandas/pull/59492#issuecomment-2338729574

--------------


Bisecting two years ago ( https://github.com/pandas-dev/pandas/issues/47101#issuecomment-1139606268 ) shows this regression was introduced in b2d54d9 in 2021. Somehow this hasn't been patched since then.

PR #48313 was supposed to address this, but the PR was closed and never merged and the bug has persisted.

Patch takes two tracks -- it first replaces the `arr == x` with [`np.equals()`](https://numpy.org/doc/1.26/reference/generated/numpy.equal.html) which will handle broadcasting in most cases by itself. For the remainder of cases, an explicit type check is done to return an array for the mask.

- [x] closes #47101
- [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
- [ ] 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.
- [ ] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature.

----------------

Has a KNOWN test failure of

> ```
> ruff-format.............................................................................................Failed
> - hook id: ruff-format
> - files were modified by this hook
> ```

but I honestly have no clue what's failing in that. Some inscrutable and poorly reported style problem?
This pull request is stale because it has been open for thirty days with no activity. Please [update](https://pandas.pydata.org/pandas-docs/stable/development/contributing.html#updating-your-pull-request) and respond to this comment if you're still interested in working on this. It's still a valid PR

- via Pixel 8pro (pardon insane autocorrects) -

On Wed, Oct 9, 2024, 17:07 github-actions[bot] ***@***.***>
wrote:

> This pull request is stale because it has been open for thirty days with
> no activity. Please update
> <https://pandas.pydata.org/pandas-docs/stable/development/contributing.html#updating-your-pull-request>
> and respond to this comment if you're still interested in working on this.
>
> —
> Reply to this email directly, view it on GitHub
> <https://github.com/pandas-dev/pandas/pull/59766#issuecomment-2403646772>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AABIQMJA2DVTSMYOLTW6GK3Z2XALZAVCNFSM6AAAAABN5F37KCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMBTGY2DMNZXGI>
> .
> You are receiving this because you authored the thread.Message ID:
> ***@***.***>
>
 Thanks for the pull request, but it appears to have gone stale. If interested in continuing, please merge in the main branch, address any review comments and/or failing tests, and we can reopen.