Skip to content

Commit 9822573

Browse files
committed
Merge remote-tracking branch 'upstream/master' into soxofaan-style_bar_axis_none
2 parents 336f4bc + bdb6168 commit 9822573

Some content is hidden

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

50 files changed

+4146
-3921
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
^^^^^^^^^^
@@ -426,6 +428,7 @@ Other
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`)
428430
- :meth: `~pandas.io.formats.style.Styler.bar` now also supports tablewise application (in addition to rowwise and columnwise) with ``axis=None`` and setting clipping range with ``vmin`` and ``vmax`` (:issue:`21548` and :issue:`21526`)
431+
- :meth: `~pandas.io.formats.style.Styler.background_gradient` now also supports tablewise application (in addition to rowwise and columnwise) with ``axis=None`` (:issue:`15204`)
429432
-
430433
-
431434
-

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/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)

pandas/_libs/src/datetime/np_datetime.h

+4-27
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,6 @@ This file is derived from NumPy 1.7. See NUMPY_LICENSE.txt
1919

2020
#include <numpy/ndarraytypes.h>
2121

22-
typedef enum {
23-
PANDAS_FR_Y = 0, // Years
24-
PANDAS_FR_M = 1, // Months
25-
PANDAS_FR_W = 2, // Weeks
26-
// Gap where NPY_FR_B was
27-
PANDAS_FR_D = 4, // Days
28-
PANDAS_FR_h = 5, // hours
29-
PANDAS_FR_m = 6, // minutes
30-
PANDAS_FR_s = 7, // seconds
31-
PANDAS_FR_ms = 8, // milliseconds
32-
PANDAS_FR_us = 9, // microseconds
33-
PANDAS_FR_ns = 10, // nanoseconds
34-
PANDAS_FR_ps = 11, // picoseconds
35-
PANDAS_FR_fs = 12, // femtoseconds
36-
PANDAS_FR_as = 13, // attoseconds
37-
PANDAS_FR_GENERIC = 14 // Generic, unbound units, can
38-
// convert to anything
39-
} PANDAS_DATETIMEUNIT;
40-
41-
#define PANDAS_DATETIME_NUMUNITS 13
42-
43-
#define PANDAS_DATETIME_NAT NPY_MIN_INT64
44-
4522
typedef struct {
4623
npy_int64 year;
4724
npy_int32 month, day, hour, min, sec, us, ps, as;
@@ -61,14 +38,14 @@ extern const pandas_datetimestruct _NS_MAX_DTS;
6138
int convert_pydatetime_to_datetimestruct(PyObject *obj,
6239
pandas_datetimestruct *out);
6340

64-
npy_datetime pandas_datetimestruct_to_datetime(PANDAS_DATETIMEUNIT fr,
41+
npy_datetime pandas_datetimestruct_to_datetime(NPY_DATETIMEUNIT fr,
6542
pandas_datetimestruct *d);
6643

67-
void pandas_datetime_to_datetimestruct(npy_datetime val, PANDAS_DATETIMEUNIT fr,
44+
void pandas_datetime_to_datetimestruct(npy_datetime val, NPY_DATETIMEUNIT fr,
6845
pandas_datetimestruct *result);
6946

7047
void pandas_timedelta_to_timedeltastruct(npy_timedelta val,
71-
PANDAS_DATETIMEUNIT fr,
48+
NPY_DATETIMEUNIT fr,
7249
pandas_timedeltastruct *result);
7350

7451
int dayofweek(int y, int m, int d);
@@ -103,7 +80,7 @@ add_minutes_to_datetimestruct(pandas_datetimestruct *dts, int minutes);
10380

10481

10582
int
106-
convert_datetime_to_datetimestruct(PANDAS_DATETIMEUNIT base,
83+
convert_datetime_to_datetimestruct(NPY_DATETIMEUNIT base,
10784
npy_datetime dt,
10885
pandas_datetimestruct *out);
10986

0 commit comments

Comments
 (0)