REF: Separate out DataFrame/Series Construction Helpers
State: closed

Why?  In implementing #24096 I found it tough to tell all the paths by which a DatetimeIndex get passed to a DataFrame or Series.  Collecting all these helper functions is a step towards reducing the number of paths available so these things can be caught in one place.

The main thing this PR does is move helper functions from core.series and core.frame.  A few ancillary things it does
- remove runtime imports (there is only one left in construction.py)
- use ABC classes for isinstance checks
- nested functions `_try_cast` and `_get_axes` are de-nested
- de-privatize functions that are imported elsewhere.  A function in construction.py has a leading underscore if and only if it is not imported elsewhere.

Labels:
name: Internals
description: Related to non-user accessible pandas implementation
name: Clean

Comments:
Hello @jbrockmendel! Thanks for submitting the PR.

 - There are no PEP8 issues in the file [`pandas/core/arrays/categorical.py`](https://github.com/jbrockmendel/pandas/blob/4f0cf906344cabafaec42c19172953e7ed15cb16/pandas/core/arrays/categorical.py) !

 - There are no PEP8 issues in the file [`pandas/core/arrays/sparse.py`](https://github.com/jbrockmendel/pandas/blob/4f0cf906344cabafaec42c19172953e7ed15cb16/pandas/core/arrays/sparse.py) !

 - There are no PEP8 issues in the file [`pandas/core/frame.py`](https://github.com/jbrockmendel/pandas/blob/4f0cf906344cabafaec42c19172953e7ed15cb16/pandas/core/frame.py) !

 - There are no PEP8 issues in the file [`pandas/core/internals/construction.py`](https://github.com/jbrockmendel/pandas/blob/4f0cf906344cabafaec42c19172953e7ed15cb16/pandas/core/internals/construction.py) !

 - There are no PEP8 issues in the file [`pandas/core/series.py`](https://github.com/jbrockmendel/pandas/blob/4f0cf906344cabafaec42c19172953e7ed15cb16/pandas/core/series.py) !

 - There are no PEP8 issues in the file [`pandas/core/sparse/frame.py`](https://github.com/jbrockmendel/pandas/blob/4f0cf906344cabafaec42c19172953e7ed15cb16/pandas/core/sparse/frame.py) !


# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/24100?src=pr&el=h1) Report
> Merging [#24100](https://codecov.io/gh/pandas-dev/pandas/pull/24100?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/4b5f4d1a59a7fce09c47eb0c03ba99a6cea472c6?src=pr&el=desc) will **decrease** coverage by `49.67%`.
> The diff coverage is `62.79%`.

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

```diff
@@             Coverage Diff             @@
##           master   #24100       +/-   ##
===========================================
- Coverage   92.21%   42.53%   -49.68%     
===========================================
  Files         161      162        +1     
  Lines       51684    51713       +29     
===========================================
- Hits        47658    21998    -25660     
- Misses       4026    29715    +25689
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `?` | |
| #single | `42.53% <62.79%> (-0.47%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/24100?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/series.py](https://codecov.io/gh/pandas-dev/pandas/pull/24100/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvc2VyaWVzLnB5) | `48.39% <100%> (-45.29%)` | :arrow_down: |
| [pandas/core/arrays/categorical.py](https://codecov.io/gh/pandas-dev/pandas/pull/24100/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL2NhdGVnb3JpY2FsLnB5) | `41.89% <100%> (-53.52%)` | :arrow_down: |
| [pandas/core/arrays/sparse.py](https://codecov.io/gh/pandas-dev/pandas/pull/24100/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL3NwYXJzZS5weQ==) | `44.84% <100%> (-47.12%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/24100/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `35.92% <50%> (-61.11%)` | :arrow_down: |
| [pandas/core/internals/construction.py](https://codecov.io/gh/pandas-dev/pandas/pull/24100/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW50ZXJuYWxzL2NvbnN0cnVjdGlvbi5weQ==) | `62.59% <62.59%> (ø)` | |
| [pandas/core/sparse/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/24100/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvc3BhcnNlL2ZyYW1lLnB5) | `27.46% <66.66%> (-67.38%)` | :arrow_down: |
| [pandas/io/formats/latex.py](https://codecov.io/gh/pandas-dev/pandas/pull/24100/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvbGF0ZXgucHk=) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/core/categorical.py](https://codecov.io/gh/pandas-dev/pandas/pull/24100/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY2F0ZWdvcmljYWwucHk=) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/io/sas/sas\_constants.py](https://codecov.io/gh/pandas-dev/pandas/pull/24100/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3Nhcy9zYXNfY29uc3RhbnRzLnB5) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/tseries/plotting.py](https://codecov.io/gh/pandas-dev/pandas/pull/24100/diff?src=pr&el=tree#diff-cGFuZGFzL3RzZXJpZXMvcGxvdHRpbmcucHk=) | `0% <0%> (-100%)` | :arrow_down: |
| ... and [125 more](https://codecov.io/gh/pandas-dev/pandas/pull/24100/diff?src=pr&el=tree-more) | |

------

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

# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/24100?src=pr&el=h1) Report
> Merging [#24100](https://codecov.io/gh/pandas-dev/pandas/pull/24100?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/4b5f4d1a59a7fce09c47eb0c03ba99a6cea472c6?src=pr&el=desc) will **decrease** coverage by `<.01%`.
> The diff coverage is `96.44%`.

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

```diff
@@            Coverage Diff             @@
##           master   #24100      +/-   ##
==========================================
- Coverage   92.21%    92.2%   -0.01%     
==========================================
  Files         161      162       +1     
  Lines       51684    51700      +16     
==========================================
+ Hits        47658    47672      +14     
- Misses       4026     4028       +2
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.6% <96.44%> (-0.01%)` | :arrow_down: |
| #single | `43.02% <64.69%> (+0.01%)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/24100?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/sparse/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/24100/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvc3BhcnNlL2ZyYW1lLnB5) | `94.84% <100%> (+0.01%)` | :arrow_up: |
| [pandas/core/series.py](https://codecov.io/gh/pandas-dev/pandas/pull/24100/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvc2VyaWVzLnB5) | `93.69% <100%> (+0.01%)` | :arrow_up: |
| [pandas/core/arrays/categorical.py](https://codecov.io/gh/pandas-dev/pandas/pull/24100/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL2NhdGVnb3JpY2FsLnB5) | `95.4% <100%> (ø)` | :arrow_up: |
| [pandas/core/arrays/sparse.py](https://codecov.io/gh/pandas-dev/pandas/pull/24100/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL3NwYXJzZS5weQ==) | `91.95% <100%> (ø)` | :arrow_up: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/24100/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `96.79% <91.66%> (-0.23%)` | :arrow_down: |
| [pandas/core/internals/construction.py](https://codecov.io/gh/pandas-dev/pandas/pull/24100/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW50ZXJuYWxzL2NvbnN0cnVjdGlvbi5weQ==) | `96.62% <96.62%> (ø)` | |

------

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

thanks. prob should open an issue with a todo list for followups.