Skip to content

Commit f9ebb39

Browse files
committed
Merge branch 'master' of https://github.com/pandas-dev/pandas into clean-df-combine-first
2 parents 143fdf1 + dcaa5c2 commit f9ebb39

File tree

144 files changed

+3165
-2112
lines changed

Some content is hidden

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

144 files changed

+3165
-2112
lines changed

.pre-commit-config.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ repos:
119119
entry: python scripts/validate_unwanted_patterns.py --validation-type="private_function_across_module"
120120
types: [python]
121121
exclude: ^(asv_bench|pandas/tests|doc)/
122+
- id: inconsistent-namespace-usage
123+
name: 'Check for inconsistent use of pandas namespace in tests'
124+
entry: python scripts/check_for_inconsistent_pandas_namespace.py
125+
language: python
126+
types: [python]
127+
files: ^pandas/tests/
122128
- id: FrameOrSeriesUnion
123129
name: Check for use of Union[Series, DataFrame] instead of FrameOrSeriesUnion alias
124130
entry: Union\[.*(Series.*DataFrame|DataFrame.*Series).*\]

ci/code_checks.sh

-13
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@ function invgrep {
3737
return $((! $EXIT_STATUS))
3838
}
3939

40-
function check_namespace {
41-
local -r CLASS=${1}
42-
grep -R -l --include "*.py" " ${CLASS}(" pandas/tests | xargs grep -n "pd\.${CLASS}[(\.]"
43-
test $? -gt 0
44-
}
45-
4640
if [[ "$GITHUB_ACTIONS" == "true" ]]; then
4741
FLAKE8_FORMAT="##[error]%(path)s:%(row)s:%(col)s:%(code)s:%(text)s"
4842
INVGREP_PREPEND="##[error]"
@@ -120,13 +114,6 @@ if [[ -z "$CHECK" || "$CHECK" == "patterns" ]]; then
120114
MSG='Check for use of {foo!r} instead of {repr(foo)}' ; echo $MSG
121115
invgrep -R --include=*.{py,pyx} '!r}' pandas
122116
RET=$(($RET + $?)) ; echo $MSG "DONE"
123-
124-
# -------------------------------------------------------------------------
125-
MSG='Check for inconsistent use of pandas namespace in tests' ; echo $MSG
126-
for class in "Series" "DataFrame" "Index" "MultiIndex" "Timestamp" "Timedelta" "TimedeltaIndex" "DatetimeIndex" "Categorical"; do
127-
check_namespace ${class}
128-
RET=$(($RET + $?))
129-
done
130117
echo $MSG "DONE"
131118
fi
132119

doc/source/whatsnew/v1.1.5.rst

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Fixed regressions
2424
Bug fixes
2525
~~~~~~~~~
2626
- Bug in metadata propagation for ``groupby`` iterator (:issue:`37343`)
27+
- Bug in indexing on a :class:`Series` with ``CategoricalDtype`` after unpickling (:issue:`37631`)
28+
- Bug in :class:`RollingGroupby` with the resulting :class:`MultiIndex` when grouping by a label that is in the index (:issue:`37641`)
2729
-
2830

2931
.. ---------------------------------------------------------------------------

doc/source/whatsnew/v1.2.0.rst

+8-2
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ Other enhancements
231231
- :class:`Window` now supports all Scipy window types in ``win_type`` with flexible keyword argument support (:issue:`34556`)
232232
- :meth:`testing.assert_index_equal` now has a ``check_order`` parameter that allows indexes to be checked in an order-insensitive manner (:issue:`37478`)
233233
- :func:`read_csv` supports memory-mapping for compressed files (:issue:`37621`)
234+
- Improve error reporting for :meth:`DataFrame.merge()` when invalid merge column definitions were given (:issue:`16228`)
235+
- Improve numerical stability for :meth:`Rolling.skew()`, :meth:`Rolling.kurt()`, :meth:`Expanding.skew()` and :meth:`Expanding.kurt()` through implementation of Kahan summation (:issue:`6929`)
234236

235237
.. _whatsnew_120.api_breaking.python:
236238

@@ -380,7 +382,7 @@ Categorical
380382
^^^^^^^^^^^
381383
- :meth:`Categorical.fillna` will always return a copy, will validate a passed fill value regardless of whether there are any NAs to fill, and will disallow a ``NaT`` as a fill value for numeric categories (:issue:`36530`)
382384
- Bug in :meth:`Categorical.__setitem__` that incorrectly raised when trying to set a tuple value (:issue:`20439`)
383-
-
385+
- Bug in :meth:`CategoricalIndex.equals` incorrectly casting non-category entries to ``np.nan`` (:issue:`37667`)
384386

385387
Datetimelike
386388
^^^^^^^^^^^^
@@ -412,7 +414,7 @@ Timezones
412414
^^^^^^^^^
413415

414416
- Bug in :func:`date_range` was raising AmbiguousTimeError for valid input with ``ambiguous=False`` (:issue:`35297`)
415-
-
417+
- Bug in :meth:`Timestamp.replace` was losing fold information (:issue:`37610`)
416418

417419

418420
Numeric
@@ -465,6 +467,8 @@ Indexing
465467
- Bug in indexing on a :class:`Series` or :class:`DataFrame` with a :class:`MultiIndex` with a level named "0" (:issue:`37194`)
466468
- Bug in :meth:`Series.__getitem__` when using an unsigned integer array as an indexer giving incorrect results or segfaulting instead of raising ``KeyError`` (:issue:`37218`)
467469
- Bug in :meth:`Index.where` incorrectly casting numeric values to strings (:issue:`37591`)
470+
- Bug in :meth:`Series.loc` and :meth:`DataFrame.loc` raises when numeric label was given for object :class:`Index` although label was in :class:`Index` (:issue:`26491`)
471+
- Bug in :meth:`DataFrame.loc` returned requested key plus missing values when ``loc`` was applied to single level from :class:`MultiIndex` (:issue:`27104`)
468472

469473
Missing
470474
^^^^^^^
@@ -510,6 +514,8 @@ Plotting
510514
- Bug in :meth:`DataFrame.plot` was rotating xticklabels when ``subplots=True``, even if the x-axis wasn't an irregular time series (:issue:`29460`)
511515
- Bug in :meth:`DataFrame.plot` where a marker letter in the ``style`` keyword sometimes causes a ``ValueError`` (:issue:`21003`)
512516
- Twinned axes were losing their tick labels which should only happen to all but the last row or column of 'externally' shared axes (:issue:`33819`)
517+
- Bug in :meth:`DataFrameGroupBy.boxplot` when ``subplots=False``, a KeyError would raise (:issue:`16748`)
518+
513519

514520
Groupby/resample/rolling
515521
^^^^^^^^^^^^^^^^^^^^^^^^

pandas/_libs/tslibs/nattype.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ default 'raise'
774774
microsecond : int, optional
775775
nanosecond : int, optional
776776
tzinfo : tz-convertible, optional
777-
fold : int, optional, default is 0
777+
fold : int, optional
778778
779779
Returns
780780
-------

pandas/_libs/tslibs/period.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2316,7 +2316,7 @@ class Period(_Period):
23162316
freq : str, default None
23172317
One of pandas period strings or corresponding objects.
23182318
ordinal : int, default None
2319-
The period offset from the gregorian proleptic epoch.
2319+
The period offset from the proleptic Gregorian epoch.
23202320
year : int, default None
23212321
Year value of the period.
23222322
month : int, default 1

pandas/_libs/tslibs/timestamps.pyx

+7-2
Original file line numberDiff line numberDiff line change
@@ -1374,7 +1374,7 @@ default 'raise'
13741374
microsecond=None,
13751375
nanosecond=None,
13761376
tzinfo=object,
1377-
fold=0,
1377+
fold=None,
13781378
):
13791379
"""
13801380
implements datetime.replace, handles nanoseconds.
@@ -1390,7 +1390,7 @@ default 'raise'
13901390
microsecond : int, optional
13911391
nanosecond : int, optional
13921392
tzinfo : tz-convertible, optional
1393-
fold : int, optional, default is 0
1393+
fold : int, optional
13941394
13951395
Returns
13961396
-------
@@ -1407,6 +1407,11 @@ default 'raise'
14071407
# set to naive if needed
14081408
tzobj = self.tzinfo
14091409
value = self.value
1410+
1411+
# GH 37610. Preserve fold when replacing.
1412+
if fold is None:
1413+
fold = self.fold
1414+
14101415
if tzobj is not None:
14111416
value = tz_convert_from_utc_single(value, tzobj)
14121417

pandas/_libs/tslibs/tzconversion.pxd

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ from cpython.datetime cimport tzinfo
22
from numpy cimport int64_t
33

44

5-
cdef int64_t tz_convert_utc_to_tzlocal(int64_t utc_val, tzinfo tz, bint* fold=*)
5+
cdef int64_t tz_convert_utc_to_tzlocal(
6+
int64_t utc_val, tzinfo tz, bint* fold=*
7+
) except? -1
68
cpdef int64_t tz_convert_from_utc_single(int64_t val, tzinfo tz)
79
cdef int64_t tz_localize_to_utc_single(
810
int64_t val, tzinfo tz, object ambiguous=*, object nonexistent=*

pandas/_libs/tslibs/tzconversion.pyx

+9-3
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,9 @@ cdef inline str _render_tstamp(int64_t val):
355355
# ----------------------------------------------------------------------
356356
# Timezone Conversion
357357

358-
cdef int64_t tz_convert_utc_to_tzlocal(int64_t utc_val, tzinfo tz, bint* fold=NULL):
358+
cdef int64_t tz_convert_utc_to_tzlocal(
359+
int64_t utc_val, tzinfo tz, bint* fold=NULL
360+
) except? -1:
359361
"""
360362
Parameters
361363
----------
@@ -500,9 +502,11 @@ cdef int64_t[:] _tz_convert_from_utc(const int64_t[:] vals, tzinfo tz):
500502
return converted
501503

502504

505+
# OSError may be thrown by tzlocal on windows at or close to 1970-01-01
506+
# see https://github.com/pandas-dev/pandas/pull/37591#issuecomment-720628241
503507
cdef inline int64_t _tzlocal_get_offset_components(int64_t val, tzinfo tz,
504508
bint to_utc,
505-
bint *fold=NULL):
509+
bint *fold=NULL) except? -1:
506510
"""
507511
Calculate offset in nanoseconds needed to convert the i8 representation of
508512
a datetime from a tzlocal timezone to UTC, or vice-versa.
@@ -547,8 +551,10 @@ cdef inline int64_t _tzlocal_get_offset_components(int64_t val, tzinfo tz,
547551
return int(td.total_seconds() * 1_000_000_000)
548552

549553

554+
# OSError may be thrown by tzlocal on windows at or close to 1970-01-01
555+
# see https://github.com/pandas-dev/pandas/pull/37591#issuecomment-720628241
550556
cdef int64_t _tz_convert_tzlocal_utc(int64_t val, tzinfo tz, bint to_utc=True,
551-
bint* fold=NULL):
557+
bint* fold=NULL) except? -1:
552558
"""
553559
Convert the i8 representation of a datetime from a tzlocal timezone to
554560
UTC, or vice-versa.

0 commit comments

Comments
 (0)