Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into bisect
Browse files Browse the repository at this point in the history
  • Loading branch information
simonjayhawkins committed May 18, 2022
2 parents a6cfcd8 + a160caf commit 6a8dfd2
Show file tree
Hide file tree
Showing 48 changed files with 695 additions and 286 deletions.
6 changes: 5 additions & 1 deletion doc/source/whatsnew/v1.5.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ Other enhancements
- Added ``validate`` argument to :meth:`DataFrame.join` (:issue:`46622`)
- A :class:`errors.PerformanceWarning` is now thrown when using ``string[pyarrow]`` dtype with methods that don't dispatch to ``pyarrow.compute`` methods (:issue:`42613`)
- Added ``numeric_only`` argument to :meth:`Resampler.sum`, :meth:`Resampler.prod`, :meth:`Resampler.min`, :meth:`Resampler.max`, :meth:`Resampler.first`, and :meth:`Resampler.last` (:issue:`46442`)
- ``times`` argument in :class:`.ExponentialMovingWindow` now accepts ``np.timedelta64`` (:issue:`47003`)

.. ---------------------------------------------------------------------------
.. _whatsnew_150.notable_bug_fixes:
Expand Down Expand Up @@ -493,7 +494,8 @@ retained by specifying ``group_keys=False``.
``numeric_only`` default value
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Across the DataFrame operations such as ``min``, ``sum``, and ``idxmax``, the default
Across the DataFrame and DataFrameGroupBy operations such as
``min``, ``sum``, and ``idxmax``, the default
value of the ``numeric_only`` argument, if it exists at all, was inconsistent.
Furthermore, operations with the default value ``None`` can lead to surprising
results. (:issue:`46560`)
Expand Down Expand Up @@ -523,6 +525,8 @@ gained the ``numeric_only`` argument.
- :meth:`DataFrame.cov`
- :meth:`DataFrame.idxmin`
- :meth:`DataFrame.idxmax`
- :meth:`.DataFrameGroupBy.cummin`
- :meth:`.DataFrameGroupBy.cummax`
- :meth:`.DataFrameGroupBy.idxmin`
- :meth:`.DataFrameGroupBy.idxmax`
- :meth:`.GroupBy.var`
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/src/ujson/lib/ultrajson.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Portions of code from MODP_ASCII - Ascii transformations (upper/lower, etc)
https://github.com/client9/stringencoders
Copyright (c) 2007 Nick Galbreath -- nickg [at] modp [dot] com. All rights reserved.
Numeric decoder derived from from TCL library
Numeric decoder derived from TCL library
https://www.opensource.apple.com/source/tcl/tcl-14/tcl/license.terms
* Copyright (c) 1988-1993 The Regents of the University of California.
* Copyright (c) 1994 Sun Microsystems, Inc.
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/src/ujson/lib/ultrajsondec.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Portions of code from MODP_ASCII - Ascii transformations (upper/lower, etc)
Copyright (c) 2007 Nick Galbreath -- nickg [at] modp [dot] com. All rights
reserved.
Numeric decoder derived from from TCL library
Numeric decoder derived from TCL library
https://www.opensource.apple.com/source/tcl/tcl-14/tcl/license.terms
* Copyright (c) 1988-1993 The Regents of the University of California.
* Copyright (c) 1994 Sun Microsystems, Inc.
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/src/ujson/lib/ultrajsonenc.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Portions of code from MODP_ASCII - Ascii transformations (upper/lower, etc)
Copyright (c) 2007 Nick Galbreath -- nickg [at] modp [dot] com. All rights
reserved.
Numeric decoder derived from from TCL library
Numeric decoder derived from TCL library
https://www.opensource.apple.com/source/tcl/tcl-14/tcl/license.terms
* Copyright (c) 1988-1993 The Regents of the University of California.
* Copyright (c) 1994 Sun Microsystems, Inc.
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/src/ujson/python/JSONtoObj.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Portions of code from MODP_ASCII - Ascii transformations (upper/lower, etc)
https://github.com/client9/stringencoders
Copyright (c) 2007 Nick Galbreath -- nickg [at] modp [dot] com. All rights reserved.
Numeric decoder derived from from TCL library
Numeric decoder derived from TCL library
https://www.opensource.apple.com/source/tcl/tcl-14/tcl/license.terms
* Copyright (c) 1988-1993 The Regents of the University of California.
* Copyright (c) 1994 Sun Microsystems, Inc.
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/src/ujson/python/objToJSON.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Portions of code from MODP_ASCII - Ascii transformations (upper/lower, etc)
Copyright (c) 2007 Nick Galbreath -- nickg [at] modp [dot] com. All rights
reserved.
Numeric decoder derived from from TCL library
Numeric decoder derived from TCL library
https://www.opensource.apple.com/source/tcl/tcl-14/tcl/license.terms
* Copyright (c) 1988-1993 The Regents of the University of California.
* Copyright (c) 1994 Sun Microsystems, Inc.
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/src/ujson/python/ujson.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Portions of code from MODP_ASCII - Ascii transformations (upper/lower, etc)
https://github.com/client9/stringencoders
Copyright (c) 2007 Nick Galbreath -- nickg [at] modp [dot] com. All rights reserved.
Numeric decoder derived from from TCL library
Numeric decoder derived from TCL library
https://www.opensource.apple.com/source/tcl/tcl-14/tcl/license.terms
* Copyright (c) 1988-1993 The Regents of the University of California.
* Copyright (c) 1994 Sun Microsystems, Inc.
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/src/ujson/python/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Portions of code from MODP_ASCII - Ascii transformations (upper/lower, etc)
https://github.com/client9/stringencoders
Copyright (c) 2007 Nick Galbreath -- nickg [at] modp [dot] com. All rights reserved.
Numeric decoder derived from from TCL library
Numeric decoder derived from TCL library
https://www.opensource.apple.com/source/tcl/tcl-14/tcl/license.terms
* Copyright (c) 1988-1993 The Regents of the University of California.
* Copyright (c) 1994 Sun Microsystems, Inc.
Expand Down
2 changes: 2 additions & 0 deletions pandas/_libs/tslibs/fields.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def get_start_end_field(
def get_date_field(
dtindex: npt.NDArray[np.int64], # const int64_t[:]
field: str,
reso: int = ..., # NPY_DATETIMEUNIT
) -> npt.NDArray[np.int32]: ...
def get_timedelta_field(
tdindex: npt.NDArray[np.int64], # const int64_t[:]
Expand All @@ -32,6 +33,7 @@ def isleapyear_arr(
) -> npt.NDArray[np.bool_]: ...
def build_isocalendar_sarray(
dtindex: npt.NDArray[np.int64], # const int64_t[:]
reso: int = ..., # NPY_DATETIMEUNIT
) -> np.ndarray: ...
def _get_locale_names(name_type: str, locale: str | None = ...): ...

Expand Down
35 changes: 18 additions & 17 deletions pandas/_libs/tslibs/fields.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def get_start_end_field(

@cython.wraparound(False)
@cython.boundscheck(False)
def get_date_field(const int64_t[:] dtindex, str field):
def get_date_field(const int64_t[:] dtindex, str field, NPY_DATETIMEUNIT reso=NPY_FR_ns):
"""
Given a int64-based datetime index, extract the year, month, etc.,
field and return an array of these values.
Expand All @@ -348,7 +348,7 @@ def get_date_field(const int64_t[:] dtindex, str field):
out[i] = -1
continue

dt64_to_dtstruct(dtindex[i], &dts)
pandas_datetime_to_datetimestruct(dtindex[i], reso, &dts)
out[i] = dts.year
return out

Expand All @@ -359,7 +359,7 @@ def get_date_field(const int64_t[:] dtindex, str field):
out[i] = -1
continue

dt64_to_dtstruct(dtindex[i], &dts)
pandas_datetime_to_datetimestruct(dtindex[i], reso, &dts)
out[i] = dts.month
return out

Expand All @@ -370,7 +370,7 @@ def get_date_field(const int64_t[:] dtindex, str field):
out[i] = -1
continue

dt64_to_dtstruct(dtindex[i], &dts)
pandas_datetime_to_datetimestruct(dtindex[i], reso, &dts)
out[i] = dts.day
return out

Expand All @@ -381,8 +381,9 @@ def get_date_field(const int64_t[:] dtindex, str field):
out[i] = -1
continue

dt64_to_dtstruct(dtindex[i], &dts)
pandas_datetime_to_datetimestruct(dtindex[i], reso, &dts)
out[i] = dts.hour
# TODO: can we de-dup with period.pyx <accessor>s?
return out

elif field == 'm':
Expand All @@ -392,7 +393,7 @@ def get_date_field(const int64_t[:] dtindex, str field):
out[i] = -1
continue

dt64_to_dtstruct(dtindex[i], &dts)
pandas_datetime_to_datetimestruct(dtindex[i], reso, &dts)
out[i] = dts.min
return out

Expand All @@ -403,7 +404,7 @@ def get_date_field(const int64_t[:] dtindex, str field):
out[i] = -1
continue

dt64_to_dtstruct(dtindex[i], &dts)
pandas_datetime_to_datetimestruct(dtindex[i], reso, &dts)
out[i] = dts.sec
return out

Expand All @@ -414,7 +415,7 @@ def get_date_field(const int64_t[:] dtindex, str field):
out[i] = -1
continue

dt64_to_dtstruct(dtindex[i], &dts)
pandas_datetime_to_datetimestruct(dtindex[i], reso, &dts)
out[i] = dts.us
return out

Expand All @@ -425,7 +426,7 @@ def get_date_field(const int64_t[:] dtindex, str field):
out[i] = -1
continue

dt64_to_dtstruct(dtindex[i], &dts)
pandas_datetime_to_datetimestruct(dtindex[i], reso, &dts)
out[i] = dts.ps // 1000
return out
elif field == 'doy':
Expand All @@ -435,7 +436,7 @@ def get_date_field(const int64_t[:] dtindex, str field):
out[i] = -1
continue

dt64_to_dtstruct(dtindex[i], &dts)
pandas_datetime_to_datetimestruct(dtindex[i], reso, &dts)
out[i] = get_day_of_year(dts.year, dts.month, dts.day)
return out

Expand All @@ -446,7 +447,7 @@ def get_date_field(const int64_t[:] dtindex, str field):
out[i] = -1
continue

dt64_to_dtstruct(dtindex[i], &dts)
pandas_datetime_to_datetimestruct(dtindex[i], reso, &dts)
out[i] = dayofweek(dts.year, dts.month, dts.day)
return out

Expand All @@ -457,7 +458,7 @@ def get_date_field(const int64_t[:] dtindex, str field):
out[i] = -1
continue

dt64_to_dtstruct(dtindex[i], &dts)
pandas_datetime_to_datetimestruct(dtindex[i], reso, &dts)
out[i] = get_week_of_year(dts.year, dts.month, dts.day)
return out

Expand All @@ -468,7 +469,7 @@ def get_date_field(const int64_t[:] dtindex, str field):
out[i] = -1
continue

dt64_to_dtstruct(dtindex[i], &dts)
pandas_datetime_to_datetimestruct(dtindex[i], reso, &dts)
out[i] = dts.month
out[i] = ((out[i] - 1) // 3) + 1
return out
Expand All @@ -480,11 +481,11 @@ def get_date_field(const int64_t[:] dtindex, str field):
out[i] = -1
continue

dt64_to_dtstruct(dtindex[i], &dts)
pandas_datetime_to_datetimestruct(dtindex[i], reso, &dts)
out[i] = get_days_in_month(dts.year, dts.month)
return out
elif field == 'is_leap_year':
return isleapyear_arr(get_date_field(dtindex, 'Y'))
return isleapyear_arr(get_date_field(dtindex, 'Y', reso=reso))

raise ValueError(f"Field {field} not supported")

Expand Down Expand Up @@ -564,7 +565,7 @@ cpdef isleapyear_arr(ndarray years):

@cython.wraparound(False)
@cython.boundscheck(False)
def build_isocalendar_sarray(const int64_t[:] dtindex):
def build_isocalendar_sarray(const int64_t[:] dtindex, NPY_DATETIMEUNIT reso=NPY_FR_ns):
"""
Given a int64-based datetime array, return the ISO 8601 year, week, and day
as a structured array.
Expand Down Expand Up @@ -592,7 +593,7 @@ def build_isocalendar_sarray(const int64_t[:] dtindex):
if dtindex[i] == NPY_NAT:
ret_val = 0, 0, 0
else:
dt64_to_dtstruct(dtindex[i], &dts)
pandas_datetime_to_datetimestruct(dtindex[i], reso, &dts)
ret_val = get_iso_calendar(dts.year, dts.month, dts.day)

iso_years[i] = ret_val[0]
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/array_algos/putmask.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
EA-compatible analogue to to np.putmask
EA-compatible analogue to np.putmask
"""
from __future__ import annotations

Expand Down
6 changes: 3 additions & 3 deletions pandas/core/arrays/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def f(self):
values, field, self.freqstr, month_kw, reso=self._reso
)
else:
result = fields.get_date_field(values, field)
result = fields.get_date_field(values, field, reso=self._reso)

# these return a boolean by-definition
return result
Expand All @@ -146,7 +146,7 @@ def f(self):
result = self._maybe_mask_results(result, fill_value=None)

else:
result = fields.get_date_field(values, field)
result = fields.get_date_field(values, field, reso=self._reso)
result = self._maybe_mask_results(
result, fill_value=None, convert="float64"
)
Expand Down Expand Up @@ -1403,7 +1403,7 @@ def isocalendar(self) -> DataFrame:
from pandas import DataFrame

values = self._local_timestamps()
sarray = fields.build_isocalendar_sarray(values)
sarray = fields.build_isocalendar_sarray(values, reso=self._reso)
iso_calendar_df = DataFrame(
sarray, columns=["year", "week", "day"], dtype="UInt32"
)
Expand Down
Loading

0 comments on commit 6a8dfd2

Please sign in to comment.