Skip to content

Commit a030ede

Browse files
committed
merge in latest master
2 parents b977e52 + bdb6168 commit a030ede

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+4590
-4182
lines changed

doc/source/whatsnew/v0.24.0.txt

+3
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ Datetimelike
301301
^^^^^^^^^^^^
302302

303303
- Fixed bug where two :class:`DateOffset` objects with different ``normalize`` attributes could evaluate as equal (:issue:`21404`)
304+
- Fixed bug where :meth:`Timestamp.resolution` incorrectly returned 1-microsecond ``timedelta`` instead of 1-nanosecond :class:`Timedelta` (:issue:`21336`,:issue:`21365`)
304305

305306
Timedelta
306307
^^^^^^^^^
@@ -369,6 +370,7 @@ Missing
369370
^^^^^^^
370371

371372
- Bug in :func:`DataFrame.fillna` where a ``ValueError`` would raise when one column contained a ``datetime64[ns, tz]`` dtype (:issue:`15522`)
373+
- Bug in :func:`Series.hasnans` that could be incorrectly cached and return incorrect answers if null elements are introduced after an initial call (:issue:`19700`)
372374

373375
MultiIndex
374376
^^^^^^^^^^
@@ -425,5 +427,6 @@ Other
425427

426428
- :meth: `~pandas.io.formats.style.Styler.background_gradient` now takes a ``text_color_threshold`` parameter to automatically lighten the text color based on the luminance of the background color. This improves readability with dark background colors without the need to limit the background colormap range. (:issue:`21258`)
427429
- Require at least 0.28.2 version of ``cython`` to support read-only memoryviews (:issue:`21688`)
430+
- :meth: `~pandas.io.formats.style.Styler.background_gradient` now also supports tablewise application (in addition to rowwise and columnwise) with ``axis=None`` (:issue:`15204`)
428431
-
429432
-

pandas/_libs/__init__.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
# -*- coding: utf-8 -*-
22
# flake8: noqa
33

4-
from .tslibs import iNaT, NaT, Timestamp, Timedelta, OutOfBoundsDatetime
5-
6-
# TODO
7-
# period is directly dependent on tslib and imports python
8-
# modules, so exposing Period as an alias is currently not possible
9-
# from period import Period
4+
from .tslibs import (
5+
iNaT, NaT, Timestamp, Timedelta, OutOfBoundsDatetime, Period)

pandas/_libs/index.pyx

+4-13
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ cdef inline bint is_definitely_invalid_key(object val):
4343
or PyList_Check(val) or hasattr(val, '_data'))
4444

4545

46-
def get_value_at(ndarray arr, object loc):
46+
cpdef get_value_at(ndarray arr, object loc, object tz=None):
4747
if arr.descr.type_num == NPY_DATETIME:
48-
return Timestamp(util.get_value_at(arr, loc))
48+
return Timestamp(util.get_value_at(arr, loc), tz=tz)
4949
elif arr.descr.type_num == NPY_TIMEDELTA:
5050
return Timedelta(util.get_value_at(arr, loc))
5151
return util.get_value_at(arr, loc)
@@ -68,12 +68,7 @@ cpdef object get_value_box(ndarray arr, object loc):
6868
if i >= sz or sz == 0 or i < 0:
6969
raise IndexError('index out of bounds')
7070

71-
if arr.descr.type_num == NPY_DATETIME:
72-
return Timestamp(util.get_value_1d(arr, i))
73-
elif arr.descr.type_num == NPY_TIMEDELTA:
74-
return Timedelta(util.get_value_1d(arr, i))
75-
else:
76-
return util.get_value_1d(arr, i)
71+
return get_value_at(arr, i, tz=None)
7772

7873

7974
# Don't populate hash tables in monotonic indexes larger than this
@@ -114,11 +109,7 @@ cdef class IndexEngine:
114109
if PySlice_Check(loc) or cnp.PyArray_Check(loc):
115110
return arr[loc]
116111
else:
117-
if arr.descr.type_num == NPY_DATETIME:
118-
return Timestamp(util.get_value_at(arr, loc), tz=tz)
119-
elif arr.descr.type_num == NPY_TIMEDELTA:
120-
return Timedelta(util.get_value_at(arr, loc))
121-
return util.get_value_at(arr, loc)
112+
return get_value_at(arr, loc, tz=tz)
122113

123114
cpdef set_value(self, ndarray arr, object key, object value):
124115
"""

pandas/_libs/indexing.pyx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# cython: profile=False
22

33
cdef class _NDFrameIndexerBase:
4-
'''
4+
"""
55
A base class for _NDFrameIndexer for fast instantiation and attribute
66
access.
7-
'''
7+
"""
88
cdef public object obj, name, _ndim
99

1010
def __init__(self, name, obj):

pandas/_libs/src/datetime/np_datetime.c

+35-34
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ This file is derived from NumPy 1.7. See NUMPY_LICENSE.txt
2121

2222
#include <numpy/arrayobject.h>
2323
#include <numpy/arrayscalars.h>
24+
#include <numpy/ndarraytypes.h>
2425
#include "np_datetime.h"
2526

2627
#if PY_MAJOR_VERSION >= 3
@@ -511,21 +512,21 @@ int convert_pydatetime_to_datetimestruct(PyObject *obj,
511512
return -1;
512513
}
513514

514-
npy_datetime pandas_datetimestruct_to_datetime(PANDAS_DATETIMEUNIT fr,
515+
npy_datetime pandas_datetimestruct_to_datetime(NPY_DATETIMEUNIT fr,
515516
pandas_datetimestruct *d) {
516-
npy_datetime result = PANDAS_DATETIME_NAT;
517+
npy_datetime result = NPY_DATETIME_NAT;
517518

518519
convert_datetimestruct_to_datetime(fr, d, &result);
519520
return result;
520521
}
521522

522-
void pandas_datetime_to_datetimestruct(npy_datetime val, PANDAS_DATETIMEUNIT fr,
523+
void pandas_datetime_to_datetimestruct(npy_datetime val, NPY_DATETIMEUNIT fr,
523524
pandas_datetimestruct *result) {
524525
convert_datetime_to_datetimestruct(fr, val, result);
525526
}
526527

527528
void pandas_timedelta_to_timedeltastruct(npy_timedelta val,
528-
PANDAS_DATETIMEUNIT fr,
529+
NPY_DATETIMEUNIT fr,
529530
pandas_timedeltastruct *result) {
530531
convert_timedelta_to_timedeltastruct(fr, val, result);
531532
}
@@ -537,71 +538,71 @@ void pandas_timedelta_to_timedeltastruct(npy_timedelta val,
537538
*
538539
* Returns 0 on success, -1 on failure.
539540
*/
540-
int convert_datetimestruct_to_datetime(PANDAS_DATETIMEUNIT base,
541+
int convert_datetimestruct_to_datetime(NPY_DATETIMEUNIT base,
541542
const pandas_datetimestruct *dts,
542543
npy_datetime *out) {
543544
npy_datetime ret;
544545

545-
if (base == PANDAS_FR_Y) {
546+
if (base == NPY_FR_Y) {
546547
/* Truncate to the year */
547548
ret = dts->year - 1970;
548-
} else if (base == PANDAS_FR_M) {
549+
} else if (base == NPY_FR_M) {
549550
/* Truncate to the month */
550551
ret = 12 * (dts->year - 1970) + (dts->month - 1);
551552
} else {
552553
/* Otherwise calculate the number of days to start */
553554
npy_int64 days = get_datetimestruct_days(dts);
554555

555556
switch (base) {
556-
case PANDAS_FR_W:
557+
case NPY_FR_W:
557558
/* Truncate to weeks */
558559
if (days >= 0) {
559560
ret = days / 7;
560561
} else {
561562
ret = (days - 6) / 7;
562563
}
563564
break;
564-
case PANDAS_FR_D:
565+
case NPY_FR_D:
565566
ret = days;
566567
break;
567-
case PANDAS_FR_h:
568+
case NPY_FR_h:
568569
ret = days * 24 + dts->hour;
569570
break;
570-
case PANDAS_FR_m:
571+
case NPY_FR_m:
571572
ret = (days * 24 + dts->hour) * 60 + dts->min;
572573
break;
573-
case PANDAS_FR_s:
574+
case NPY_FR_s:
574575
ret = ((days * 24 + dts->hour) * 60 + dts->min) * 60 + dts->sec;
575576
break;
576-
case PANDAS_FR_ms:
577+
case NPY_FR_ms:
577578
ret = (((days * 24 + dts->hour) * 60 + dts->min) * 60 +
578579
dts->sec) *
579580
1000 +
580581
dts->us / 1000;
581582
break;
582-
case PANDAS_FR_us:
583+
case NPY_FR_us:
583584
ret = (((days * 24 + dts->hour) * 60 + dts->min) * 60 +
584585
dts->sec) *
585586
1000000 +
586587
dts->us;
587588
break;
588-
case PANDAS_FR_ns:
589+
case NPY_FR_ns:
589590
ret = ((((days * 24 + dts->hour) * 60 + dts->min) * 60 +
590591
dts->sec) *
591592
1000000 +
592593
dts->us) *
593594
1000 +
594595
dts->ps / 1000;
595596
break;
596-
case PANDAS_FR_ps:
597+
case NPY_FR_ps:
597598
ret = ((((days * 24 + dts->hour) * 60 + dts->min) * 60 +
598599
dts->sec) *
599600
1000000 +
600601
dts->us) *
601602
1000000 +
602603
dts->ps;
603604
break;
604-
case PANDAS_FR_fs:
605+
case NPY_FR_fs:
605606
/* only 2.6 hours */
606607
ret = (((((days * 24 + dts->hour) * 60 + dts->min) * 60 +
607608
dts->sec) *
@@ -612,7 +613,7 @@ int convert_datetimestruct_to_datetime(PANDAS_DATETIMEUNIT base,
612613
1000 +
613614
dts->as / 1000;
614615
break;
615-
case PANDAS_FR_as:
616+
case NPY_FR_as:
616617
/* only 9.2 secs */
617618
ret = (((((days * 24 + dts->hour) * 60 + dts->min) * 60 +
618619
dts->sec) *
@@ -640,7 +641,7 @@ int convert_datetimestruct_to_datetime(PANDAS_DATETIMEUNIT base,
640641
/*
641642
* Converts a datetime based on the given metadata into a datetimestruct
642643
*/
643-
int convert_datetime_to_datetimestruct(PANDAS_DATETIMEUNIT base,
644+
int convert_datetime_to_datetimestruct(NPY_DATETIMEUNIT base,
644645
npy_datetime dt,
645646
pandas_datetimestruct *out) {
646647
npy_int64 perday;
@@ -656,11 +657,11 @@ int convert_datetime_to_datetimestruct(PANDAS_DATETIMEUNIT base,
656657
* for negative values.
657658
*/
658659
switch (base) {
659-
case PANDAS_FR_Y:
660+
case NPY_FR_Y:
660661
out->year = 1970 + dt;
661662
break;
662663

663-
case PANDAS_FR_M:
664+
case NPY_FR_M:
664665
if (dt >= 0) {
665666
out->year = 1970 + dt / 12;
666667
out->month = dt % 12 + 1;
@@ -670,16 +671,16 @@ int convert_datetime_to_datetimestruct(PANDAS_DATETIMEUNIT base,
670671
}
671672
break;
672673

673-
case PANDAS_FR_W:
674+
case NPY_FR_W:
674675
/* A week is 7 days */
675676
set_datetimestruct_days(dt * 7, out);
676677
break;
677678

678-
case PANDAS_FR_D:
679+
case NPY_FR_D:
679680
set_datetimestruct_days(dt, out);
680681
break;
681682

682-
case PANDAS_FR_h:
683+
case NPY_FR_h:
683684
perday = 24LL;
684685

685686
if (dt >= 0) {
@@ -693,7 +694,7 @@ int convert_datetime_to_datetimestruct(PANDAS_DATETIMEUNIT base,
693694
out->hour = dt;
694695
break;
695696

696-
case PANDAS_FR_m:
697+
case NPY_FR_m:
697698
perday = 24LL * 60;
698699

699700
if (dt >= 0) {
@@ -708,7 +709,7 @@ int convert_datetime_to_datetimestruct(PANDAS_DATETIMEUNIT base,
708709
out->min = dt % 60;
709710
break;
710711

711-
case PANDAS_FR_s:
712+
case NPY_FR_s:
712713
perday = 24LL * 60 * 60;
713714

714715
if (dt >= 0) {
@@ -724,7 +725,7 @@ int convert_datetime_to_datetimestruct(PANDAS_DATETIMEUNIT base,
724725
out->sec = dt % 60;
725726
break;
726727

727-
case PANDAS_FR_ms:
728+
case NPY_FR_ms:
728729
perday = 24LL * 60 * 60 * 1000;
729730

730731
if (dt >= 0) {
@@ -741,7 +742,7 @@ int convert_datetime_to_datetimestruct(PANDAS_DATETIMEUNIT base,
741742
out->us = (dt % 1000LL) * 1000;
742743
break;
743744

744-
case PANDAS_FR_us:
745+
case NPY_FR_us:
745746
perday = 24LL * 60LL * 60LL * 1000LL * 1000LL;
746747

747748
if (dt >= 0) {
@@ -758,7 +759,7 @@ int convert_datetime_to_datetimestruct(PANDAS_DATETIMEUNIT base,
758759
out->us = dt % 1000000LL;
759760
break;
760761

761-
case PANDAS_FR_ns:
762+
case NPY_FR_ns:
762763
perday = 24LL * 60LL * 60LL * 1000LL * 1000LL * 1000LL;
763764

764765
if (dt >= 0) {
@@ -776,7 +777,7 @@ int convert_datetime_to_datetimestruct(PANDAS_DATETIMEUNIT base,
776777
out->ps = (dt % 1000LL) * 1000;
777778
break;
778779

779-
case PANDAS_FR_ps:
780+
case NPY_FR_ps:
780781
perday = 24LL * 60 * 60 * 1000 * 1000 * 1000 * 1000;
781782

782783
if (dt >= 0) {
@@ -794,7 +795,7 @@ int convert_datetime_to_datetimestruct(PANDAS_DATETIMEUNIT base,
794795
out->ps = dt % 1000000LL;
795796
break;
796797

797-
case PANDAS_FR_fs:
798+
case NPY_FR_fs:
798799
/* entire range is only +- 2.6 hours */
799800
if (dt >= 0) {
800801
out->hour = dt / (60 * 60 * 1000000000000000LL);
@@ -821,7 +822,7 @@ int convert_datetime_to_datetimestruct(PANDAS_DATETIMEUNIT base,
821822
}
822823
break;
823824

824-
case PANDAS_FR_as:
825+
case NPY_FR_as:
825826
/* entire range is only +- 9.2 seconds */
826827
if (dt >= 0) {
827828
out->sec = (dt / 1000000000000000000LL) % 60;
@@ -861,7 +862,7 @@ int convert_datetime_to_datetimestruct(PANDAS_DATETIMEUNIT base,
861862
*
862863
* Returns 0 on success, -1 on failure.
863864
*/
864-
int convert_timedelta_to_timedeltastruct(PANDAS_DATETIMEUNIT base,
865+
int convert_timedelta_to_timedeltastruct(NPY_DATETIMEUNIT base,
865866
npy_timedelta td,
866867
pandas_timedeltastruct *out) {
867868
npy_int64 frac;
@@ -874,7 +875,7 @@ int convert_timedelta_to_timedeltastruct(PANDAS_DATETIMEUNIT base,
874875
memset(out, 0, sizeof(pandas_timedeltastruct));
875876

876877
switch (base) {
877-
case PANDAS_FR_ns:
878+
case NPY_FR_ns:
878879

879880
// put frac in seconds
880881
if (td < 0 && td % (1000LL * 1000LL * 1000LL) != 0)

0 commit comments

Comments
 (0)