Separate conversion functions out from tslib
State: closed

The functions moved are cut/paste with two exceptions: a flake8 whitespace fixup and the new helper function `conversion._render_tstamp`.

About half of the remaining `_TSObject` conversion funcs can be moved once #17805 is merged.  The remainder can be isolated after #17793.

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

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



Cheers ! There are no PEP8 issues in this Pull Request. :beers: 

##### Comment last updated on October 29, 2017 at 22:06 Hours UTC
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/17875?src=pr&el=h1) Report
> Merging [#17875](https://codecov.io/gh/pandas-dev/pandas/pull/17875?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/528fdaa80c847fd1c186dbdd3db061b993b557c0?src=pr&el=desc) will **decrease** coverage by `0.01%`.
> The diff coverage is `n/a`.

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

```diff
@@            Coverage Diff             @@
##           master   #17875      +/-   ##
==========================================
- Coverage   91.23%   91.21%   -0.02%     
==========================================
  Files         163      163              
  Lines       50102    50102              
==========================================
- Hits        45712    45703       -9     
- Misses       4390     4399       +9
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `89.03% <ø> (ø)` | :arrow_up: |
| #single | `40.31% <ø> (-0.06%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/17875?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/17875?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/17875?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.75% <0%> (-0.1%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/17875?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/17875?src=pr&el=footer). Last update [528fdaa...dfd4979](https://codecov.io/gh/pandas-dev/pandas/pull/17875?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/17875?src=pr&el=h1) Report
> Merging [#17875](https://codecov.io/gh/pandas-dev/pandas/pull/17875?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/a355ed2a8c32a29c1dc93466f9b65870cac272fa?src=pr&el=desc) will **decrease** coverage by `0.04%`.
> The diff coverage is `n/a`.

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

```diff
@@            Coverage Diff             @@
##           master   #17875      +/-   ##
==========================================
- Coverage   91.26%   91.22%   -0.05%     
==========================================
  Files         163      163              
  Lines       50099    50099              
==========================================
- Hits        45724    45703      -21     
- Misses       4375     4396      +21
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `89.03% <ø> (-0.03%)` | :arrow_down: |
| #single | `40.24% <ø> (-0.06%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/17875?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/17875?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |
| [pandas/plotting/\_converter.py](https://codecov.io/gh/pandas-dev/pandas/pull/17875?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL19jb252ZXJ0ZXIucHk=) | `63.38% <0%> (-1.82%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/17875?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.75% <0%> (-0.1%)` | :arrow_down: |

------

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

rebase
if we accep this PR, what then? this just moves the conversion functions out but doesn't actually simplify things AFAICT. what is the next step?
> this just moves the conversion functions out but doesn't actually simplify things AFAICT

You're absolutely right.  Keep in mind that to make reviewing easier I'm trying to strictly separate cut/paste PRs from actual-changes PRs.

Three goals in mind:

- Refactoring/Cleanup for its own sake.  Separating out all the TSObject logic results in a ~1k line module, which is "about right" for my tastes.  (Note we can't get _all_ the TSObject logic out just now.  The remaining chunks will come after #17805 and a soon-to-be-opened follow-up to #17793)

- There is at least one bug in the tz_convert/tso_localize/... code; the hope is these will be easier to track down once this is isolated.

- Part of the over-arching MO is to avoid the run-time import of `frequencies.to_offset` in `tslib` and `period`.  I've _mostly_ gotten this downstream, but not completely.  Separating out the conversion functions helps solidify the dependency structure as a DAG.
needs a rebase
Since this has already been reviewed in its current form, my preference is to close it out and then follow-up with to use e.g. `dtstruct_to_dt64` and other improvements that have become available with recent merges.
thanks!
Awesome!

There's some accumulated cleanup that needs to be done.  Quick question since micro-optimizations matter here.  Do we need to care about the difference between:

```
int(get_utcoffset(tzinfo, ts)) * 1000000000
int(get_utcoffset(tzinfo, ts) * 1e9)
```

?