Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into cow_replace
Browse files Browse the repository at this point in the history
  • Loading branch information
phofl committed Jan 21, 2023
2 parents e8f2c3f + 185c53f commit 16dbe9a
Show file tree
Hide file tree
Showing 45 changed files with 276 additions and 223 deletions.
19 changes: 2 additions & 17 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,8 @@ fi
### DOCSTRINGS ###
if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then

MSG='Validate docstrings (EX04, GL01, GL02, GL03, GL04, GL05, GL06, GL07, GL09, GL10, PR03, PR04, PR05, PR06, PR08, PR09, PR10, RT01, RT04, RT05, SA02, SA03, SA04, SS01, SS02, SS03, SS04, SS05, SS06)' ; echo $MSG
$BASE_DIR/scripts/validate_docstrings.py --format=actions --errors=EX04,GL01,GL02,GL03,GL04,GL05,GL06,GL07,GL09,GL10,PR03,PR04,PR05,PR06,PR08,PR09,PR10,RT01,RT04,RT05,SA02,SA03,SA04,SS01,SS02,SS03,SS04,SS05,SS06
RET=$(($RET + $?)) ; echo $MSG "DONE"

MSG='Partially validate docstrings (RT02)' ; echo $MSG
$BASE_DIR/scripts/validate_docstrings.py --format=actions --errors=RT02 --ignore_functions \
pandas.Index.all \
pandas.Index.any \
pandas.MultiIndex.drop \
pandas.DatetimeIndex.to_pydatetime \
pandas.TimedeltaIndex.to_pytimedelta \
pandas.io.formats.style.Styler.export \
pandas.api.extensions.ExtensionArray.astype \
pandas.api.extensions.ExtensionArray.dropna \
pandas.api.extensions.ExtensionArray.isna \
pandas.api.extensions.ExtensionArray.repeat \
pandas.api.extensions.ExtensionArray.unique
MSG='Validate docstrings (EX04, GL01, GL02, GL03, GL04, GL05, GL06, GL07, GL09, GL10, PR03, PR04, PR05, PR06, PR08, PR09, PR10, RT01, RT02, RT04, RT05, SA02, SA03, SA04, SS01, SS02, SS03, SS04, SS05, SS06)' ; echo $MSG
$BASE_DIR/scripts/validate_docstrings.py --format=actions --errors=EX04,GL01,GL02,GL03,GL04,GL05,GL06,GL07,GL09,GL10,PR03,PR04,PR05,PR06,PR08,PR09,PR10,RT01,RT02,RT04,RT05,SA02,SA03,SA04,SS01,SS02,SS03,SS04,SS05,SS06
RET=$(($RET + $?)) ; echo $MSG "DONE"

fi
Expand Down
2 changes: 1 addition & 1 deletion doc/source/development/contributing_gitpod.rst
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ docs you need to run the following command in the docs directory::

Alternatively you can build a single page with::

python make.py html python make.py --single development/contributing_gitpod.rst
python make.py --single development/contributing_gitpod.rst

You have two main options to render the documentation in Gitpod.

Expand Down
2 changes: 1 addition & 1 deletion doc/source/user_guide/timeseries.rst
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ The default behavior, ``errors='raise'``, is to raise when unparsable:
.. code-block:: ipython
In [2]: pd.to_datetime(['2009/07/31', 'asd'], errors='raise')
ValueError: Unknown string format
ValueError: Unknown datetime string format
Pass ``errors='ignore'`` to return the original input when unparsable:

Expand Down
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ Other enhancements
- Improved error message in :func:`to_datetime` for non-ISO8601 formats, informing users about the position of the first error (:issue:`50361`)
- Improved error message when trying to align :class:`DataFrame` objects (for example, in :func:`DataFrame.compare`) to clarify that "identically labelled" refers to both index and columns (:issue:`50083`)
- Added :meth:`DatetimeIndex.as_unit` and :meth:`TimedeltaIndex.as_unit` to convert to different resolutions; supported resolutions are "s", "ms", "us", and "ns" (:issue:`50616`)
- Added new argument ``dtype`` to :func:`read_sql` to be consistent with :func:`read_sql_query` (:issue:`50797`)
-

.. ---------------------------------------------------------------------------
Expand Down Expand Up @@ -950,6 +951,7 @@ Datetimelike
- Bug in :func:`to_datetime` was failing to parse date strings ``'today'`` and ``'now'`` if ``format`` was not ISO8601 (:issue:`50359`)
- Bug in :func:`Timestamp.utctimetuple` raising a ``TypeError`` (:issue:`32174`)
- Bug in :func:`to_datetime` was raising ``ValueError`` when parsing mixed-offset :class:`Timestamp` with ``errors='ignore'`` (:issue:`50585`)
- Bug in :func:`to_datetime` was incorrectly handling floating-point inputs within 1 ``unit`` of the overflow boundaries (:issue:`50183`)

Timedelta
^^^^^^^^^
Expand Down
4 changes: 2 additions & 2 deletions pandas/_libs/lib.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,6 @@ def get_reverse_indexer(
) -> npt.NDArray[np.intp]: ...
def is_bool_list(obj: list) -> bool: ...
def dtypes_all_equal(types: list[DtypeObj]) -> bool: ...
def array_equal_fast(
left: np.ndarray, right: np.ndarray # np.ndarray[np.int64, ndim=1]
def is_range_indexer(
left: np.ndarray, n: int # np.ndarray[np.int64, ndim=1]
) -> bool: ...
10 changes: 4 additions & 6 deletions pandas/_libs/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -650,22 +650,20 @@ ctypedef fused int6432_t:

@cython.wraparound(False)
@cython.boundscheck(False)
def array_equal_fast(
ndarray[int6432_t, ndim=1] left, ndarray[int6432_t, ndim=1] right,
) -> bool:
def is_range_indexer(ndarray[int6432_t, ndim=1] left, int n) -> bool:
"""
Perform an element by element comparison on 1-d integer arrays, meant for indexer
comparisons
"""
cdef:
Py_ssize_t i, n = left.size
Py_ssize_t i

if left.size != right.size:
if left.size != n:
return False

for i in range(n):

if left[i] != right[i]:
if left[i] != i:
return False

return True
Expand Down
12 changes: 3 additions & 9 deletions pandas/_libs/tslib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def array_with_unit_to_datetime(
bint is_coerce = errors=="coerce"
bint is_raise = errors=="raise"
ndarray[int64_t] iresult
object tz = None
tzinfo tz = None
float fval

assert is_ignore or is_coerce or is_raise
Expand Down Expand Up @@ -346,7 +346,7 @@ cdef _array_with_unit_to_datetime_object_fallback(ndarray[object] values, str un
cdef:
Py_ssize_t i, n = len(values)
ndarray[object] oresult
object tz = None
tzinfo tz = None

# TODO: fix subtle differences between this and no-unit code
oresult = cnp.PyArray_EMPTY(values.ndim, values.shape, cnp.NPY_OBJECT, 0)
Expand Down Expand Up @@ -497,15 +497,9 @@ cpdef array_to_datetime(

if val != val or val == NPY_NAT:
iresult[i] = NPY_NAT
elif is_raise or is_ignore:
iresult[i] = val
else:
# coerce
# we now need to parse this as if unit='ns'
try:
iresult[i] = cast_from_unit(val, "ns")
except OverflowError:
iresult[i] = NPY_NAT
iresult[i] = cast_from_unit(val, "ns")

elif isinstance(val, str):
# string
Expand Down
13 changes: 3 additions & 10 deletions pandas/_libs/tslibs/conversion.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -544,16 +544,9 @@ cdef _TSObject convert_str_to_tsobject(str ts, tzinfo tz, str unit,
maybe_localize_tso(obj, tz, obj.creso)
return obj

try:
dt = parse_datetime_string(
ts, dayfirst=dayfirst, yearfirst=yearfirst
)
except ValueError as err:
if "out of range for month" in str(err):
# dateutil raised when constructing a datetime object,
# let's give a nicer exception message
raise ValueError("could not convert string to Timestamp") from err
raise
dt = parse_datetime_string(
ts, dayfirst=dayfirst, yearfirst=yearfirst
)

return convert_datetime_to_tsobject(dt, tz)

Expand Down
1 change: 1 addition & 0 deletions pandas/_libs/tslibs/dtypes.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ cpdef int64_t periods_per_second(NPY_DATETIMEUNIT reso) except? -1
cpdef NPY_DATETIMEUNIT get_supported_reso(NPY_DATETIMEUNIT reso)

cdef dict attrname_to_abbrevs
cdef dict npy_unit_to_attrname

cdef enum c_FreqGroup:
# Mirrors FreqGroup in the .pyx file
Expand Down
12 changes: 12 additions & 0 deletions pandas/_libs/tslibs/dtypes.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -423,3 +423,15 @@ cdef dict _reso_str_map = {
}

cdef dict _str_reso_map = {v: k for k, v in _reso_str_map.items()}

cdef dict npy_unit_to_attrname = {
NPY_DATETIMEUNIT.NPY_FR_Y: "year",
NPY_DATETIMEUNIT.NPY_FR_M: "month",
NPY_DATETIMEUNIT.NPY_FR_D: "day",
NPY_DATETIMEUNIT.NPY_FR_h: "hour",
NPY_DATETIMEUNIT.NPY_FR_m: "minute",
NPY_DATETIMEUNIT.NPY_FR_s: "second",
NPY_DATETIMEUNIT.NPY_FR_ms: "millisecond",
NPY_DATETIMEUNIT.NPY_FR_us: "microsecond",
NPY_DATETIMEUNIT.NPY_FR_ns: "nanosecond",
}
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/offsets.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2792,7 +2792,7 @@ cdef class Week(SingleConstructorOffset):
2nd week of each month.

Examples
---------
--------

>>> date_object = pd.Timestamp("2023-01-13")
>>> date_object
Expand Down
Loading

0 comments on commit 16dbe9a

Please sign in to comment.