 BUG: AttributeError: 'function' object has no attribute 'currentframe' 
- [x] closes #48733  (Replace xxxx with the Github issue number)
- [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).
- [ ] 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.

Note how `pylint` would've caught this:
```
$ pylint pandas/io/sql.py | grep 'inspect'
pandas/io/sql.py:1648:12: W0621: Redefining name 'inspect' from outer scope (line 15) (redefined-outer-name)
pandas/io/sql.py:1648:12: C0415: Import outside toplevel (sqlalchemy.inspect) (import-outside-toplevel)
pandas/io/sql.py:1663:48: E1101: Function 'inspect' has no 'currentframe' member (no-member)
pandas/io/sql.py:1760:8: W0621: Redefining name 'inspect' from outer scope (line 15) (redefined-outer-name)
pandas/io/sql.py:1760:8: C0415: Import outside toplevel (sqlalchemy.inspect) (import-outside-toplevel)
```

We should add that to CI
Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

1. Checkout backport branch and update it.

```
git checkout 1.5.x
git pull
```

2. Cherry pick the first parent branch of the this PR on top of the older branch:
```
git cherry-pick -x -m1 e0608cb42e98f165fd99b595b2c9d0bfeb208b8f
```

3. You will likely have some merge/cherry-pick conflict here, fix them and commit:

```
git commit -am "Backport PR #48736:  BUG: AttributeError: 'function' object has no attribute 'currentframe' "
```

4. Push to a named branch:

```
git push YOURFORK 1.5.x:auto-backport-of-pr-48736-on-1.5.x
```

5. Create a PR against branch 1.5.x, I would have named this PR:

> "Backport PR #48736 on branch 1.5.x ( BUG: AttributeError: 'function' object has no attribute 'currentframe' )"

And apply the correct labels and milestones.

Congratulations — you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon!

Remember to remove the `Still Needs Manual Backport` label once the PR gets merged.

If these instructions are inaccurate, feel free to [suggest an improvement](https://github.com/MeeseeksBox/MeeseeksDev).
                 Thanks @MarcoGorelli. Could improve the test as @jorisvandenbossche mentioned but agreed that the existing test is good enough 