Last of the timezones funcs by jbrockmendel · Pull Request #17669 · pandas-dev/pandas (original) (raw)

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

@jbrockmendel

Moves tools.datetimes._infer_tzinfo to tslibs.timezones._infer_tzinfo.

Refactor a large timezone-specific chunk of tslib.tz_localize_to_utc to tslibs.timezones._infer_dst

The new func timezones._infer_dst is taken out of tslib.tz_localize_to_utc. It is very nearly a cut/paste. The only change is removed a couple calls to Timestamp that are used for rendering an exception message, used np.datetime64 in its place.

@jbrockmendel

refactor a large timezone-specific chunk of tslib.tz_localize_to_utc to tslibs.timezones._infer_dst

@jbrockmendel

@jbrockmendel

jreback

ndarray[int64_t] result_b):
cdef:
Py_ssize_t n = len(vals)
ndarray[int64_t] dst_hours

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sure u r typing s the original
there are lots of issues here

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The typings should be identical. There are a couple of variables that do not have type declarations; those can be added.

def _infer_tzinfo(start, end):
def _infer(a, b):
tz = a.tzinfo
if b and b.tzinfo:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is this actually used?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outside of tests, its used once in indexes.datetimes

return dst_cache[cache_key]
def _infer_tzinfo(start, end):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

de-privatize these

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

k

def _infer_tzinfo(start, end):
def _infer(a, b):
tz = a.tzinfo

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be an outside function

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're going to bother changing it, might as well get rid of _infer. It's only actually relevant in one case (of four)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

@jbrockmendel

jreback

treat_tz_as_dateutil, treat_tz_as_pytz,
get_timezone, get_utcoffset, maybe_get_tz,
get_dst_info
get_dst_info, _infer_dst

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's give this a more descriptive name: infer_dst_transitions

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

def _infer_tzinfo(start, end):
def _infer(a, b):
tz = a.tzinfo

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

return tz
cdef ndarray[int64_t] _infer_dst(ndarray[int64_t] vals,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are removing part of this function. I think its better to move almost all of it to timezones or leave it. (ok with latter for now, maybe do former at some point). Otherwise you end up splitting the logic / comments in 2 places.

I think this requires a bit more thought here.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the appropriate block to separate out. It is exclusively focused on getting DST info for use in the original function. The rest of the function is thematically more related to _TSObject conversion.

In particular, pandas_datetimestruct doesn't belong anywhere near timezones.

@jbrockmendel

@codecov

@codecov

jreback

both_eq = result_a == result_b
trans_idx = np.squeeze(np.nonzero(np.logical_and(both_nat, ~both_eq)))
if trans_idx.size == 1:
stamp = Timestamp(vals[trans_idx])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert this routine.

jreback

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just do the infer_tzinfo for now

@jreback

ok rebase, ping on green.

@jbrockmendel

@jbrockmendel

jreback

@jreback

ghost pushed a commit to reef-technologies/pandas that referenced this pull request

Oct 2, 2017

alanbato pushed a commit to alanbato/pandas that referenced this pull request

Nov 10, 2017

@jbrockmendel @alanbato

No-Stream pushed a commit to No-Stream/pandas that referenced this pull request

Nov 28, 2017

@jbrockmendel @No-Stream

Labels

2 participants

@jbrockmendel @jreback