Skip to content

Commit 981159f

Browse files
committed
idiomatic naming
1 parent 18f05c6 commit 981159f

File tree

2 files changed

+32
-35
lines changed

2 files changed

+32
-35
lines changed

pandas/_libs/tslibs/np_datetime.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ class OutOfBoundsDatetime(ValueError): ...
44

55
# only exposed for testing
66
def py_get_unit_from_dtype(dtype: np.dtype): ...
7+
def py_td64_to_tdstruct(td64: int, unit: int) -> dict: ...

pandas/_libs/tslibs/src/datetime/np_datetime.c

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -682,23 +682,23 @@ void pandas_timedelta_to_timedeltastruct(npy_timedelta td,
682682
npy_int64 sfrac;
683683
npy_int64 ifrac;
684684
int sign;
685-
npy_int64 PER_DAY;
686-
npy_int64 PER_SEC;
685+
npy_int64 per_day;
686+
npy_int64 per_sec;
687687

688688
/* Initialize the output to all zeros */
689689
memset(out, 0, sizeof(pandas_timedeltastruct));
690690

691691
switch (base) {
692692
case NPY_FR_ns:
693693

694-
PER_DAY = 86400000000000LL;
695-
PER_SEC = 1000LL * 1000LL * 1000LL;
694+
per_day = 86400000000000LL;
695+
per_sec = 1000LL * 1000LL * 1000LL;
696696

697697
// put frac in seconds
698-
if (td < 0 && td % PER_SEC != 0)
699-
frac = td / PER_SEC - 1;
698+
if (td < 0 && td % per_sec != 0)
699+
frac = td / per_sec - 1;
700700
else
701-
frac = td / PER_SEC;
701+
frac = td / per_sec;
702702

703703
if (frac < 0) {
704704
sign = -1;
@@ -742,12 +742,12 @@ void pandas_timedelta_to_timedeltastruct(npy_timedelta td,
742742
}
743743

744744
sfrac = (out->hrs * 3600LL + out->min * 60LL
745-
+ out->sec) * PER_SEC;
745+
+ out->sec) * per_sec;
746746

747747
if (sign < 0)
748748
out->days = -out->days;
749749

750-
ifrac = td - (out->days * PER_DAY + sfrac);
750+
ifrac = td - (out->days * per_day + sfrac);
751751

752752
if (ifrac != 0) {
753753
out->ms = ifrac / (1000LL * 1000LL);
@@ -760,22 +760,18 @@ void pandas_timedelta_to_timedeltastruct(npy_timedelta td,
760760
out->us = 0;
761761
out->ns = 0;
762762
}
763-
764-
out->seconds = out->hrs * 3600 + out->min * 60 + out->sec;
765-
out->microseconds = out->ms * 1000 + out->us;
766-
out->nanoseconds = out->ns;
767763
break;
768764

769765
case NPY_FR_us:
770766

771-
PER_DAY = 86400000000LL;
772-
PER_SEC = 1000LL * 1000LL;
767+
per_day = 86400000000LL;
768+
per_sec = 1000LL * 1000LL;
773769

774770
// put frac in seconds
775-
if (td < 0 && td % PER_SEC != 0)
776-
frac = td / PER_SEC - 1;
771+
if (td < 0 && td % per_sec != 0)
772+
frac = td / per_sec - 1;
777773
else
778-
frac = td / PER_SEC;
774+
frac = td / per_sec;
779775

780776
if (frac < 0) {
781777
sign = -1;
@@ -819,12 +815,12 @@ void pandas_timedelta_to_timedeltastruct(npy_timedelta td,
819815
}
820816

821817
sfrac = (out->hrs * 3600LL + out->min * 60LL
822-
+ out->sec) * PER_SEC;
818+
+ out->sec) * per_sec;
823819

824820
if (sign < 0)
825821
out->days = -out->days;
826822

827-
ifrac = td - (out->days * PER_DAY + sfrac);
823+
ifrac = td - (out->days * per_day + sfrac);
828824

829825
if (ifrac != 0) {
830826
out->ms = ifrac / 1000LL;
@@ -841,14 +837,14 @@ void pandas_timedelta_to_timedeltastruct(npy_timedelta td,
841837

842838
case NPY_FR_ms:
843839

844-
PER_DAY = 86400000LL;
845-
PER_SEC = 1000LL;
840+
per_day = 86400000LL;
841+
per_sec = 1000LL;
846842

847843
// put frac in seconds
848-
if (td < 0 && td % PER_SEC != 0)
849-
frac = td / PER_SEC - 1;
844+
if (td < 0 && td % per_sec != 0)
845+
frac = td / per_sec - 1;
850846
else
851-
frac = td / PER_SEC;
847+
frac = td / per_sec;
852848

853849
if (frac < 0) {
854850
sign = -1;
@@ -892,12 +888,12 @@ void pandas_timedelta_to_timedeltastruct(npy_timedelta td,
892888
}
893889

894890
sfrac = (out->hrs * 3600LL + out->min * 60LL
895-
+ out->sec) * PER_SEC;
891+
+ out->sec) * per_sec;
896892

897893
if (sign < 0)
898894
out->days = -out->days;
899895

900-
ifrac = td - (out->days * PER_DAY + sfrac);
896+
ifrac = td - (out->days * per_day + sfrac);
901897

902898
if (ifrac != 0) {
903899
out->ms = ifrac;
@@ -911,16 +907,16 @@ void pandas_timedelta_to_timedeltastruct(npy_timedelta td,
911907
break;
912908

913909
case NPY_FR_s:
914-
// special case where we can simplify many expressions bc PER_SEC=1
910+
// special case where we can simplify many expressions bc per_sec=1
915911

916-
PER_DAY = 86400000LL;
917-
PER_SEC = 1L;
912+
per_day = 86400000LL;
913+
per_sec = 1L;
918914

919915
// put frac in seconds
920-
if (td < 0 && td % PER_SEC != 0)
921-
frac = td / PER_SEC - 1;
916+
if (td < 0 && td % per_sec != 0)
917+
frac = td / per_sec - 1;
922918
else
923-
frac = td / PER_SEC;
919+
frac = td / per_sec;
924920

925921
if (frac < 0) {
926922
sign = -1;
@@ -964,12 +960,12 @@ void pandas_timedelta_to_timedeltastruct(npy_timedelta td,
964960
}
965961

966962
sfrac = (out->hrs * 3600LL + out->min * 60LL
967-
+ out->sec) * PER_SEC;
963+
+ out->sec) * per_sec;
968964

969965
if (sign < 0)
970966
out->days = -out->days;
971967

972-
ifrac = td - (out->days * PER_DAY + sfrac);
968+
ifrac = td - (out->days * per_day + sfrac);
973969

974970
if (ifrac != 0) {
975971
out->ms = 0;

0 commit comments

Comments
 (0)