-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Cross off a few tslibs-TODOs #18443
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cross off a few tslibs-TODOs #18443
Changes from all commits
7f96594
596383a
6ef9227
c08e4ce
c5f79d1
438662d
5dd4469
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -564,18 +564,15 @@ void pandas_datetime_to_datetimestruct(npy_datetime val, PANDAS_DATETIMEUNIT fr, | |
|
||
void pandas_timedelta_to_timedeltastruct(npy_timedelta val, | ||
PANDAS_DATETIMEUNIT fr, | ||
pandas_timedeltastruct *result) { | ||
pandas_timedeltastruct *result) { | ||
pandas_datetime_metadata meta; | ||
|
||
meta.base = fr; | ||
meta.num - 1; | ||
meta.num = 1; | ||
|
||
convert_timedelta_to_timedeltastruct(&meta, val, result); | ||
} | ||
|
||
PANDAS_DATETIMEUNIT get_datetime64_unit(PyObject *obj) { | ||
return (PANDAS_DATETIMEUNIT)((PyDatetimeScalarObject *)obj)->obmeta.base; | ||
} | ||
|
||
/* | ||
* Converts a datetime from a datetimestruct to a datetime based | ||
|
@@ -1001,7 +998,6 @@ int convert_datetime_to_datetimestruct(pandas_datetime_metadata *meta, | |
int convert_timedelta_to_timedeltastruct(pandas_timedelta_metadata *meta, | ||
npy_timedelta td, | ||
pandas_timedeltastruct *out) { | ||
npy_int64 perday; | ||
npy_int64 frac; | ||
npy_int64 sfrac; | ||
npy_int64 ifrac; | ||
|
@@ -1016,11 +1012,11 @@ int convert_timedelta_to_timedeltastruct(pandas_timedelta_metadata *meta, | |
|
||
// put frac in seconds | ||
if (td < 0 && td % (1000LL * 1000LL * 1000LL) != 0) | ||
frac = td / (1000LL * 1000LL * 1000LL) - 1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we already lint this file (cpplint). is this not picked up? rather have the proper config settings than manually changing things. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No argument here, but cpplint is well outside my domain of competence. I only noticed this indentation when trying to move this func into cython. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @WillAyd any experience with cpplint? want to give this a shot, e.g. making sure we are linting the *.c (more/better)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't claim experience with cpplint but looking at the bash script it appears to already hit all of the files in the datetime folder. I ran both versions of this file through cpplint locally and neither caused any issue with the highest level of verbosity. Surprisingly I couldn't get an error when changing the line to a 1 or 3 space indent either, so I think there might be some bug with cpplint itself. In looking at Google's style guide they suggest a 2 space indent. To match that and keep consistent with the rest of the file I would suggest removing the two spaces added here and remove the two from the indented block after the https://google.github.io/styleguide/cppguide.html#Conditionals There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see https://github.com/apache/arrow?files=1 for some hints in how to lint / enforce this as well There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you saying that within arrow cpplint is calling out those whitespace issues? I tried replicating the filters I saw in that project via:
And then tried an even more verbose version without any filter
And neither made any mention of those lines, whether I set them at 2, 4 or even 3 space indents. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no just a guess that they have more options set for linting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at the cpplint source, I don't see anything that checks for proper 2-space indentation of conditional statements, nor was there any documentation hinting that it could. The |
||
frac = td / (1000LL * 1000LL * 1000LL) - 1; | ||
else | ||
frac = td / (1000LL * 1000LL * 1000LL); | ||
|
||
if (frac < 0) { | ||
if (frac < 0) { | ||
sign = -1; | ||
|
||
// even fraction | ||
|
@@ -1030,66 +1026,66 @@ int convert_timedelta_to_timedeltastruct(pandas_timedelta_metadata *meta, | |
} else { | ||
frac = -frac; | ||
} | ||
} else { | ||
} else { | ||
sign = 1; | ||
out->days = 0; | ||
} | ||
} | ||
|
||
if (frac >= 86400) { | ||
if (frac >= 86400) { | ||
out->days += frac / 86400LL; | ||
frac -= out->days * 86400LL; | ||
} | ||
} | ||
|
||
if (frac >= 3600) { | ||
if (frac >= 3600) { | ||
out->hrs = frac / 3600LL; | ||
frac -= out->hrs * 3600LL; | ||
} else { | ||
} else { | ||
out->hrs = 0; | ||
} | ||
} | ||
|
||
if (frac >= 60) { | ||
if (frac >= 60) { | ||
out->min = frac / 60LL; | ||
frac -= out->min * 60LL; | ||
} else { | ||
} else { | ||
out->min = 0; | ||
} | ||
} | ||
|
||
if (frac >= 0) { | ||
if (frac >= 0) { | ||
out->sec = frac; | ||
frac -= out->sec; | ||
} else { | ||
} else { | ||
out->sec = 0; | ||
} | ||
} | ||
|
||
sfrac = (out->hrs * 3600LL + out->min * 60LL | ||
+ out->sec) * (1000LL * 1000LL * 1000LL); | ||
sfrac = (out->hrs * 3600LL + out->min * 60LL | ||
+ out->sec) * (1000LL * 1000LL * 1000LL); | ||
|
||
if (sign < 0) | ||
if (sign < 0) | ||
out->days = -out->days; | ||
|
||
ifrac = td - (out->days * DAY_NS + sfrac); | ||
ifrac = td - (out->days * DAY_NS + sfrac); | ||
|
||
if (ifrac != 0) { | ||
if (ifrac != 0) { | ||
out->ms = ifrac / (1000LL * 1000LL); | ||
ifrac -= out->ms * 1000LL * 1000LL; | ||
out->us = ifrac / 1000LL; | ||
ifrac -= out->us * 1000LL; | ||
out->ns = ifrac; | ||
} else { | ||
} else { | ||
out->ms = 0; | ||
out->us = 0; | ||
out->ns = 0; | ||
} | ||
} | ||
|
||
out->seconds = out->hrs * 3600 + out->min * 60 + out->sec; | ||
out->microseconds = out->ms * 1000 + out->us; | ||
out->nanoseconds = out->ns; | ||
break; | ||
out->seconds = out->hrs * 3600 + out->min * 60 + out->sec; | ||
out->microseconds = out->ms * 1000 + out->us; | ||
out->nanoseconds = out->ns; | ||
break; | ||
|
||
default: | ||
PyErr_SetString(PyExc_RuntimeError, | ||
"NumPy datetime metadata is corrupted with invalid " | ||
"base unit"); | ||
"NumPy timedelta metadata is corrupted with " | ||
"invalid base unit"); | ||
return -1; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,7 +60,7 @@ from tslibs.conversion cimport (tz_convert_single, _TSObject, | |
from tslibs.conversion import tz_convert_single | ||
|
||
from tslibs.nattype import NaT, nat_strings, iNaT | ||
from tslibs.nattype cimport _checknull_with_nat, NPY_NAT | ||
from tslibs.nattype cimport checknull_with_nat, NPY_NAT | ||
|
||
from tslibs.timestamps cimport (create_timestamp_from_ts, | ||
_NS_UPPER_BOUND, _NS_LOWER_BOUND) | ||
|
@@ -409,7 +409,7 @@ cpdef array_with_unit_to_datetime(ndarray values, unit, errors='coerce'): | |
for i in range(n): | ||
val = values[i] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these array_* should be moved to conversion I think (obviously new PR), then tslib.pyx is moot? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's hold off on that. I'd like to do auditing before moving, and the array_* funcs may need some work/thought (#17697) |
||
|
||
if _checknull_with_nat(val): | ||
if checknull_with_nat(val): | ||
iresult[i] = NPY_NAT | ||
|
||
elif is_integer_object(val) or is_float_object(val): | ||
|
@@ -475,7 +475,7 @@ cpdef array_with_unit_to_datetime(ndarray values, unit, errors='coerce'): | |
for i in range(n): | ||
val = values[i] | ||
|
||
if _checknull_with_nat(val): | ||
if checknull_with_nat(val): | ||
oresult[i] = NaT | ||
elif is_integer_object(val) or is_float_object(val): | ||
|
||
|
@@ -526,7 +526,7 @@ cpdef array_to_datetime(ndarray[object] values, errors='raise', | |
for i in range(n): | ||
val = values[i] | ||
|
||
if _checknull_with_nat(val): | ||
if checknull_with_nat(val): | ||
iresult[i] = NPY_NAT | ||
|
||
elif PyDateTime_Check(val): | ||
|
@@ -686,7 +686,7 @@ cpdef array_to_datetime(ndarray[object] values, errors='raise', | |
val = values[i] | ||
|
||
# set as nan except if its a NaT | ||
if _checknull_with_nat(val): | ||
if checknull_with_nat(val): | ||
if PyFloat_Check(val): | ||
oresult[i] = np.nan | ||
else: | ||
|
@@ -704,7 +704,7 @@ cpdef array_to_datetime(ndarray[object] values, errors='raise', | |
|
||
for i in range(n): | ||
val = values[i] | ||
if _checknull_with_nat(val): | ||
if checknull_with_nat(val): | ||
oresult[i] = val | ||
elif is_string_object(val): | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing this typo. Do we even need the assignment at all though? Worth considering removal?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm advocating moving the timedelta_struct stuff out of src/ entirely. The src/ directory is a PITA and we can put it in cython directly without taking a performance hit.