BUG: remove usage of _constructor._get_axis_number (fix when _constructor properties return callables)
State: closed

See report at https://github.com/pandas-dev/pandas/issues/32860#issuecomment-697993089 (and we also run into this one case in geopandas). Also related to https://github.com/pandas-dev/pandas/issues/32638

As far as I know this is the only remaining case where we rely on `_constructor`/`_constructor_sliced`/`_constructor_expanddim` returning a class and not a generic callable (in geopandas, we also have a workaround for this one case). 

This specific case was introduced in https://github.com/pandas-dev/pandas/pull/34837 to avoid circular dependencies/imports, so therefore I added the DataFrame import inline.

Labels:
name: Bug
name: Subclassing
description: Subclassing pandas objects

Comments:
Found one more, in `replace()` which was introduced in https://github.com/pandas-dev/pandas/pull/39152 (restored the inline import that was there before that PR)
tests are failing as well :->
Ah, that's another case, but where we didn't call a method on it, but used in an `issubclass` check. 
Are people OK with considering this for 1.4.x? (the actual change is quite small, the bulk of the diff is due to typing)

This is actually fixing a regression for geopandas, although not a regression in 1.4.0, but somewhere between 1.0 and 1.4. 
@meeseeksdev backport 1.4.x
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.4.x
git pull
```

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

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

```
git commit -am 'Backport PR #46018: BUG: remove usage of _constructor._get_axis_number (fix when _constructor properties return callables)'
```

4. Push to a named branch:

```
git push YOURFORK 1.4.x:auto-backport-of-pr-46018-on-1.4.x
```

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

> "Backport PR #46018 on branch 1.4.x (BUG: remove usage of _constructor._get_axis_number (fix when _constructor properties return callables))"

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).
                
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.4.x
git pull
```

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

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

```
git commit -am 'Backport PR #46018: BUG: remove usage of _constructor._get_axis_number (fix when _constructor properties return callables)'
```

4. Push to a named branch:

```
git push YOURFORK 1.4.x:auto-backport-of-pr-46018-on-1.4.x
```

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

> "Backport PR #46018 on branch 1.4.x (BUG: remove usage of _constructor._get_axis_number (fix when _constructor properties return callables))"

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).
                
@jorisvandenbossche if you can push a manual backport
The auto backport failed as #45272 is not backported. The changes here to that code were only the mypy comments. Those changes have therefore been omitted in the manual backport.