Skip to content

Sync Fork from Upstream Repo #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Feb 10, 2020
4 changes: 4 additions & 0 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,10 @@ if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then
pandas/core/arrays/boolean.py
RET=$(($RET + $?)) ; echo $MSG "DONE"

MSG='Doctests dtypes'; echo $MSG
pytest -q --doctest-modules pandas/core/dtypes/
RET=$(($RET + $?)) ; echo $MSG "DONE"

MSG='Doctests arrays/boolean.py' ; echo $MSG
pytest -q --doctest-modules pandas/core/arrays/boolean.py
RET=$(($RET + $?)) ; echo $MSG "DONE"
Expand Down
2 changes: 1 addition & 1 deletion doc/source/user_guide/boolean.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
.. _boolean:

**************************
Nullable Boolean Data Type
Nullable Boolean data type
**************************

.. versionadded:: 1.0.0
Expand Down
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.0.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Fixed regressions

- Fixed regression in :meth:`DataFrame.to_excel` when ``columns`` kwarg is passed (:issue:`31677`)
- Fixed regression in :meth:`Series.align` when ``other`` is a DataFrame and ``method`` is not None (:issue:`31785`)
- Fixed regression in :meth:`pandas.core.groupby.RollingGroupby.apply` where the ``raw`` parameter was ignored (:issue:`31754`)
-

.. ---------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,7 @@ def __arrow_array__(self, type=None):

Parameters
----------
na_tuple : boolean, default True
na_tuple : bool, default True
Returns NA as a tuple if True, ``(nan, nan)``, or just as the NA
value itself if False, ``nan``.

Expand Down
10 changes: 7 additions & 3 deletions pandas/core/dtypes/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
"""Extend pandas with custom array types"""
"""
Extend pandas with custom array types.
"""

from typing import Any, List, Optional, Tuple, Type

import numpy as np
Expand Down Expand Up @@ -231,8 +234,9 @@ def construct_from_string(cls, string: str):
... if match:
... return cls(**match.groupdict())
... else:
... raise TypeError(f"Cannot construct a '{cls.__name__}' from
... " "'{string}'")
... raise TypeError(
... f"Cannot construct a '{cls.__name__}' from '{string}'"
... )
"""
if not isinstance(string, str):
raise TypeError(
Expand Down
26 changes: 13 additions & 13 deletions pandas/core/dtypes/cast.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
""" routings for casting """
"""
Routines for casting.
"""

from datetime import date, datetime, timedelta

Expand Down Expand Up @@ -269,12 +271,12 @@ def maybe_upcast_putmask(result: np.ndarray, mask: np.ndarray, other):

Examples
--------
>>> result, _ = maybe_upcast_putmask(np.arange(1,6),
np.array([False, True, False, True, True]), np.arange(21,23))
>>> arr = np.arange(1, 6)
>>> mask = np.array([False, True, False, True, True])
>>> result, _ = maybe_upcast_putmask(arr, mask, False)
>>> result
array([1, 21, 3, 22, 21])
array([1, 0, 3, 0, 0])
"""

if not isinstance(result, np.ndarray):
raise ValueError("The result input must be a ndarray.")
if not is_scalar(other):
Expand Down Expand Up @@ -662,9 +664,8 @@ def infer_dtype_from_array(arr, pandas_dtype: bool = False):
array(['1', '1'], dtype='<U21')

>>> infer_dtype_from_array([1, '1'])
(numpy.object_, [1, '1'])
(<class 'numpy.object_'>, [1, '1'])
"""

if isinstance(arr, np.ndarray):
return arr.dtype, arr

Expand Down Expand Up @@ -709,7 +710,7 @@ def maybe_infer_dtype_type(element):
>>> from collections import namedtuple
>>> Foo = namedtuple("Foo", "dtype")
>>> maybe_infer_dtype_type(Foo(np.dtype("i8")))
numpy.int64
dtype('int64')
"""
tipo = None
if hasattr(element, "dtype"):
Expand Down Expand Up @@ -1555,8 +1556,8 @@ def maybe_cast_to_integer_array(arr, dtype, copy: bool = False):

Returns
-------
int_arr : ndarray
An array of integer or unsigned integer dtype
ndarray
Array of integer or unsigned integer dtype.

Raises
------
Expand All @@ -1567,19 +1568,18 @@ def maybe_cast_to_integer_array(arr, dtype, copy: bool = False):
--------
If you try to coerce negative values to unsigned integers, it raises:

>>> Series([-1], dtype="uint64")
>>> pd.Series([-1], dtype="uint64")
Traceback (most recent call last):
...
OverflowError: Trying to coerce negative values to unsigned integers

Also, if you try to coerce float values to integers, it raises:

>>> Series([1, 2, 3.5], dtype="int64")
>>> pd.Series([1, 2, 3.5], dtype="int64")
Traceback (most recent call last):
...
ValueError: Trying to coerce float values to integers
"""

try:
if not hasattr(arr, "astype"):
casted = np.array(arr, dtype=dtype, copy=copy)
Expand Down
31 changes: 15 additions & 16 deletions pandas/core/dtypes/common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
""" common type operations """
"""
Common type operations.
"""

from typing import Any, Callable, Union
import warnings

Expand Down Expand Up @@ -705,7 +708,7 @@ def is_dtype_equal(source, target) -> bool:
False
>>> is_dtype_equal(CategoricalDtype(), "category")
True
>>> is_dtype_equal(DatetimeTZDtype(), "datetime64")
>>> is_dtype_equal(DatetimeTZDtype(tz="UTC"), "datetime64")
False
"""

Expand Down Expand Up @@ -862,7 +865,7 @@ def is_signed_integer_dtype(arr_or_dtype) -> bool:
True
>>> is_signed_integer_dtype('Int8')
True
>>> is_signed_dtype(pd.Int8Dtype)
>>> is_signed_integer_dtype(pd.Int8Dtype)
True
>>> is_signed_integer_dtype(np.datetime64)
False
Expand Down Expand Up @@ -994,7 +997,7 @@ def is_datetime64_any_dtype(arr_or_dtype) -> bool:

Returns
-------
boolean
bool
Whether or not the array or dtype is of the datetime64 dtype.

Examples
Expand All @@ -1011,13 +1014,11 @@ def is_datetime64_any_dtype(arr_or_dtype) -> bool:
False
>>> is_datetime64_any_dtype(np.array([1, 2]))
False
>>> is_datetime64_any_dtype(np.array([], dtype=np.datetime64))
>>> is_datetime64_any_dtype(np.array([], dtype="datetime64[ns]"))
True
>>> is_datetime64_any_dtype(pd.DatetimeIndex([1, 2, 3],
dtype=np.datetime64))
>>> is_datetime64_any_dtype(pd.DatetimeIndex([1, 2, 3], dtype="datetime64[ns]"))
True
"""

if arr_or_dtype is None:
return False
return is_datetime64_dtype(arr_or_dtype) or is_datetime64tz_dtype(arr_or_dtype)
Expand All @@ -1034,7 +1035,7 @@ def is_datetime64_ns_dtype(arr_or_dtype) -> bool:

Returns
-------
boolean
bool
Whether or not the array or dtype is of the datetime64[ns] dtype.

Examples
Expand All @@ -1051,16 +1052,13 @@ def is_datetime64_ns_dtype(arr_or_dtype) -> bool:
False
>>> is_datetime64_ns_dtype(np.array([1, 2]))
False
>>> is_datetime64_ns_dtype(np.array([], dtype=np.datetime64)) # no unit
>>> is_datetime64_ns_dtype(np.array([], dtype="datetime64")) # no unit
False
>>> is_datetime64_ns_dtype(np.array([],
dtype="datetime64[ps]")) # wrong unit
>>> is_datetime64_ns_dtype(np.array([], dtype="datetime64[ps]")) # wrong unit
False
>>> is_datetime64_ns_dtype(pd.DatetimeIndex([1, 2, 3],
dtype=np.datetime64)) # has 'ns' unit
>>> is_datetime64_ns_dtype(pd.DatetimeIndex([1, 2, 3], dtype="datetime64[ns]"))
True
"""

if arr_or_dtype is None:
return False
try:
Expand Down Expand Up @@ -1240,7 +1238,8 @@ def is_datetimelike_v_numeric(a, b):

Examples
--------
>>> dt = np.datetime64(pd.datetime(2017, 1, 1))
>>> from datetime import datetime
>>> dt = np.datetime64(datetime(2017, 1, 1))
>>>
>>> is_datetimelike_v_numeric(1, 1)
False
Expand Down
4 changes: 3 additions & 1 deletion pandas/core/dtypes/concat.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Utility functions related to concat
Utility functions related to concat.
"""

import numpy as np
Expand Down Expand Up @@ -261,6 +261,8 @@ def union_categoricals(
>>> a = pd.Categorical(["a", "b"], ordered=True)
>>> b = pd.Categorical(["a", "b", "c"], ordered=True)
>>> union_categoricals([a, b])
Traceback (most recent call last):
...
TypeError: to union ordered Categoricals, all categories must be the same

New in version 0.20.0
Expand Down
29 changes: 18 additions & 11 deletions pandas/core/dtypes/dtypes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
""" define extension dtypes """
"""
Define extension dtypes.
"""

import re
from typing import Any, Dict, List, MutableMapping, Optional, Tuple, Type, Union, cast

Expand Down Expand Up @@ -286,23 +289,27 @@ def _from_values_or_dtype(

Examples
--------
>>> CategoricalDtype._from_values_or_dtype()
>>> pd.CategoricalDtype._from_values_or_dtype()
CategoricalDtype(categories=None, ordered=None)
>>> CategoricalDtype._from_values_or_dtype(categories=['a', 'b'],
... ordered=True)
>>> pd.CategoricalDtype._from_values_or_dtype(
... categories=['a', 'b'], ordered=True
... )
CategoricalDtype(categories=['a', 'b'], ordered=True)
>>> dtype1 = CategoricalDtype(['a', 'b'], ordered=True)
>>> dtype2 = CategoricalDtype(['x', 'y'], ordered=False)
>>> c = Categorical([0, 1], dtype=dtype1, fastpath=True)
>>> CategoricalDtype._from_values_or_dtype(c, ['x', 'y'], ordered=True,
... dtype=dtype2)
>>> dtype1 = pd.CategoricalDtype(['a', 'b'], ordered=True)
>>> dtype2 = pd.CategoricalDtype(['x', 'y'], ordered=False)
>>> c = pd.Categorical([0, 1], dtype=dtype1, fastpath=True)
>>> pd.CategoricalDtype._from_values_or_dtype(
... c, ['x', 'y'], ordered=True, dtype=dtype2
... )
Traceback (most recent call last):
...
ValueError: Cannot specify `categories` or `ordered` together with
`dtype`.

The supplied dtype takes precedence over values' dtype:

>>> CategoricalDtype._from_values_or_dtype(c, dtype=dtype2)
CategoricalDtype(['x', 'y'], ordered=False)
>>> pd.CategoricalDtype._from_values_or_dtype(c, dtype=dtype2)
CategoricalDtype(categories=['x', 'y'], ordered=False)
"""
from pandas.core.dtypes.common import is_categorical

Expand Down
5 changes: 4 additions & 1 deletion pandas/core/dtypes/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ def is_file_like(obj) -> bool:

Examples
--------
>>> buffer(StringIO("data"))
>>> import io
>>> buffer = io.StringIO("data")
>>> is_file_like(buffer)
True
>>> is_file_like([1, 2, 3])
Expand Down Expand Up @@ -311,6 +312,7 @@ def is_named_tuple(obj) -> bool:

Examples
--------
>>> from collections import namedtuple
>>> Point = namedtuple("Point", ["x", "y"])
>>> p = Point(1, 2)
>>>
Expand Down Expand Up @@ -339,6 +341,7 @@ def is_hashable(obj) -> bool:

Examples
--------
>>> import collections
>>> a = ([],)
>>> isinstance(a, collections.abc.Hashable)
True
Expand Down
8 changes: 4 additions & 4 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2933,12 +2933,12 @@ def __setitem__(self, key, value):
# set column
self._set_item(key, value)

def _setitem_slice(self, key, value):
def _setitem_slice(self, key: slice, value):
# NB: we can't just use self.loc[key] = value because that
# operates on labels and we need to operate positional for
# backwards-compat, xref GH#31469
self._check_setitem_copy()
self.loc._setitem_with_indexer(key, value)
self.iloc._setitem_with_indexer(key, value)

def _setitem_array(self, key, value):
# also raises Exception if object array with NA values
Expand All @@ -2950,7 +2950,7 @@ def _setitem_array(self, key, value):
key = check_bool_indexer(self.index, key)
indexer = key.nonzero()[0]
self._check_setitem_copy()
self.loc._setitem_with_indexer(indexer, value)
self.iloc._setitem_with_indexer(indexer, value)
else:
if isinstance(value, DataFrame):
if len(value.columns) != len(key):
Expand All @@ -2962,7 +2962,7 @@ def _setitem_array(self, key, value):
key, axis=1, raise_missing=False
)[1]
self._check_setitem_copy()
self.loc._setitem_with_indexer((slice(None), indexer), value)
self.iloc._setitem_with_indexer((slice(None), indexer), value)

def _setitem_frame(self, key, value):
# support boolean setting with DataFrame input, e.g.
Expand Down
3 changes: 2 additions & 1 deletion pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -2336,7 +2336,8 @@ def shift(self, periods=1, freq=None, axis=0, fill_value=None):
----------
periods : int, default 1
Number of periods to shift.
freq : frequency string
freq : str, optional
Frequency string
axis : axis to shift, default 0
fill_value : optional

Expand Down
Loading