Skip to content

Commit

Permalink
Replaced numpy type aliases; fix CI failure (#34835)
Browse files Browse the repository at this point in the history
  • Loading branch information
WillAyd authored Jun 17, 2020
1 parent 107ad15 commit 72aed3e
Show file tree
Hide file tree
Showing 73 changed files with 247 additions and 277 deletions.
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/pandas_vb_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
np.uint8,
]
datetime_dtypes = [np.datetime64, np.timedelta64]
string_dtypes = [np.object]
string_dtypes = [object]
try:
extension_dtypes = [
pd.Int8Dtype,
Expand Down
18 changes: 8 additions & 10 deletions asv_bench/benchmarks/series_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,15 @@ def time_isin_nan_values(self):

class IsInForObjects:
def setup(self):
self.s_nans = Series(np.full(10 ** 4, np.nan)).astype(np.object)
self.vals_nans = np.full(10 ** 4, np.nan).astype(np.object)
self.s_short = Series(np.arange(2)).astype(np.object)
self.s_long = Series(np.arange(10 ** 5)).astype(np.object)
self.vals_short = np.arange(2).astype(np.object)
self.vals_long = np.arange(10 ** 5).astype(np.object)
self.s_nans = Series(np.full(10 ** 4, np.nan)).astype(object)
self.vals_nans = np.full(10 ** 4, np.nan).astype(object)
self.s_short = Series(np.arange(2)).astype(object)
self.s_long = Series(np.arange(10 ** 5)).astype(object)
self.vals_short = np.arange(2).astype(object)
self.vals_long = np.arange(10 ** 5).astype(object)
# because of nans floats are special:
self.s_long_floats = Series(np.arange(10 ** 5, dtype=np.float)).astype(
np.object
)
self.vals_long_floats = np.arange(10 ** 5, dtype=np.float).astype(np.object)
self.s_long_floats = Series(np.arange(10 ** 5, dtype=np.float)).astype(object)
self.vals_long_floats = np.arange(10 ** 5, dtype=np.float).astype(object)

def time_isin_nans(self):
# if nan-objects are different objects,
Expand Down
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def time_series_to_frame(self):

class SparseArrayConstructor:

params = ([0.1, 0.01], [0, np.nan], [np.int64, np.float64, np.object])
params = ([0.1, 0.01], [0, np.nan], [np.int64, np.float64, object])
param_names = ["dense_proportion", "fill_value", "dtype"]

def setup(self, dense_proportion, fill_value, dtype):
Expand Down
2 changes: 1 addition & 1 deletion doc/source/user_guide/io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1884,7 +1884,7 @@ Fallback behavior
If the JSON serializer cannot handle the container contents directly it will
fall back in the following manner:

* if the dtype is unsupported (e.g. ``np.complex``) then the ``default_handler``, if provided, will be called
* if the dtype is unsupported (e.g. ``np.complex_``) then the ``default_handler``, if provided, will be called
for each value, otherwise an exception is raised.

* if an object is unsupported it will attempt the following:
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/hashtable_class_helper.pxi.in
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ cdef class StringVector:
Py_ssize_t n
object val

ao = np.empty(self.data.n, dtype=np.object)
ao = np.empty(self.data.n, dtype=object)
for i in range(self.data.n):
val = self.data.data[i]
ao[i] = val
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/hashtable_func_helper.pxi.in
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ cpdef value_count_{{dtype}}({{c_type}}[:] values, bint dropna):
build_count_table_{{dtype}}(values, table, dropna)
{{endif}}

result_keys = np.empty(table.n_occupied, dtype=np.{{dtype}})
result_keys = np.empty(table.n_occupied, '{{dtype}}')
result_counts = np.zeros(table.n_occupied, dtype=np.int64)

{{if dtype == 'object'}}
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/parsers.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2037,7 +2037,7 @@ def _concatenate_chunks(list chunks):
numpy_dtypes = {x for x in dtypes if not is_categorical_dtype(x)}
if len(numpy_dtypes) > 1:
common_type = np.find_common_type(numpy_dtypes, [])
if common_type == np.object:
if common_type == object:
warning_columns.append(str(name))

dtype = dtypes.pop()
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/sparse.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -791,4 +791,4 @@ def make_mask_object_ndarray(ndarray[object, ndim=1] arr, object fill_value):
if value == fill_value and type(value) == type(fill_value):
mask[i] = 0

return mask.view(dtype=np.bool)
return mask.view(dtype=bool)
2 changes: 1 addition & 1 deletion pandas/_libs/testing.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ cdef NUMERIC_TYPES = (
bool,
int,
float,
np.bool,
np.bool_,
np.int8,
np.int16,
np.int32,
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def _ensure_data(
return values, dtype

# we have failed, return object
values = np.asarray(values, dtype=np.object)
values = np.asarray(values, dtype=object)
return ensure_object(values), np.dtype("object")


Expand Down
4 changes: 2 additions & 2 deletions pandas/core/arrays/sparse/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def _sparse_array_op(
# to make template simple, cast here
left_sp_values = left.sp_values.view(np.uint8)
right_sp_values = right.sp_values.view(np.uint8)
result_dtype = np.bool
result_dtype = bool
else:
opname = f"sparse_{name}_{dtype}"
left_sp_values = left.sp_values
Expand Down Expand Up @@ -183,7 +183,7 @@ def _wrap_result(name, data, sparse_index, fill_value, dtype=None):
name = name[2:-2]

if name in ("eq", "ne", "lt", "gt", "le", "ge"):
dtype = np.bool
dtype = bool

fill_value = lib.item_from_zerodim(fill_value)

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1520,7 +1520,7 @@ def drop_duplicates(self, keep="first"):
def duplicated(self, keep="first"):
if isinstance(self, ABCIndexClass):
if self.is_unique:
return np.zeros(len(self), dtype=np.bool)
return np.zeros(len(self), dtype=bool)
return duplicated(self, keep=keep)
else:
return self._constructor(
Expand Down
10 changes: 5 additions & 5 deletions pandas/core/dtypes/cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def trans(x):
# if we have any nulls, then we are done
return result

elif not isinstance(r[0], (np.integer, np.floating, np.bool, int, float, bool)):
elif not isinstance(r[0], (np.integer, np.floating, int, float, bool)):
# a comparable, e.g. a Decimal may slip in here
return result

Expand Down Expand Up @@ -315,7 +315,7 @@ def maybe_cast_result_dtype(dtype: DtypeObj, how: str) -> DtypeObj:
from pandas.core.arrays.boolean import BooleanDtype
from pandas.core.arrays.integer import Int64Dtype

if how in ["add", "cumsum", "sum"] and (dtype == np.dtype(np.bool)):
if how in ["add", "cumsum", "sum"] and (dtype == np.dtype(bool)):
return np.dtype(np.int64)
elif how in ["add", "cumsum", "sum"] and isinstance(dtype, BooleanDtype):
return Int64Dtype()
Expand Down Expand Up @@ -597,7 +597,7 @@ def _ensure_dtype_type(value, dtype):
"""
Ensure that the given value is an instance of the given dtype.
e.g. if out dtype is np.complex64, we should have an instance of that
e.g. if out dtype is np.complex64_, we should have an instance of that
as opposed to a python complex object.
Parameters
Expand Down Expand Up @@ -1483,7 +1483,7 @@ def find_common_type(types: List[DtypeObj]) -> DtypeObj:
if has_bools:
for t in types:
if is_integer_dtype(t) or is_float_dtype(t) or is_complex_dtype(t):
return np.object
return object

return np.find_common_type(types, [])

Expand Down Expand Up @@ -1742,7 +1742,7 @@ def validate_numeric_casting(dtype: np.dtype, value):
if is_float(value) and np.isnan(value):
raise ValueError("Cannot assign nan to integer series")

if issubclass(dtype.type, (np.integer, np.floating, np.complex)) and not issubclass(
if issubclass(dtype.type, (np.integer, np.floating, complex)) and not issubclass(
dtype.type, np.bool_
):
if is_bool(value):
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/dtypes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1354,7 +1354,7 @@ def is_bool_dtype(arr_or_dtype) -> bool:
False
>>> is_bool_dtype(bool)
True
>>> is_bool_dtype(np.bool)
>>> is_bool_dtype(np.bool_)
True
>>> is_bool_dtype(np.array(['a', 'b']))
False
Expand Down Expand Up @@ -1526,7 +1526,7 @@ def is_complex_dtype(arr_or_dtype) -> bool:
False
>>> is_complex_dtype(int)
False
>>> is_complex_dtype(np.complex)
>>> is_complex_dtype(np.complex_)
True
>>> is_complex_dtype(np.array(['a', 'b']))
False
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -10024,7 +10024,7 @@ def describe(
Including only string columns in a ``DataFrame`` description.
>>> df.describe(include=[np.object]) # doctest: +SKIP
>>> df.describe(include=[object]) # doctest: +SKIP
object
count 3
unique 3
Expand All @@ -10051,7 +10051,7 @@ def describe(
Excluding object columns from a ``DataFrame`` description.
>>> df.describe(exclude=[np.object]) # doctest: +SKIP
>>> df.describe(exclude=[object]) # doctest: +SKIP
categorical numeric
count 3 3.0
unique 3 NaN
Expand Down
6 changes: 3 additions & 3 deletions pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -1267,9 +1267,9 @@ def objs_to_bool(vals: np.ndarray) -> Tuple[np.ndarray, Type]:
if is_object_dtype(vals):
vals = np.array([bool(x) for x in vals])
else:
vals = vals.astype(np.bool)
vals = vals.astype(bool)

return vals.view(np.uint8), np.bool
return vals.view(np.uint8), bool

def result_to_bool(result: np.ndarray, inference: Type) -> np.ndarray:
return result.astype(inference, copy=False)
Expand Down Expand Up @@ -2059,7 +2059,7 @@ def pre_processor(vals: np.ndarray) -> Tuple[np.ndarray, Optional[Type]]:
vals = vals.to_numpy(dtype=float, na_value=np.nan)
elif is_datetime64_dtype(vals.dtype):
inference = "datetime64[ns]"
vals = np.asarray(vals).astype(np.float)
vals = np.asarray(vals).astype(float)

return vals, inference

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ def __new__(
return UInt64Index(data, copy=copy, dtype=dtype, name=name)
elif is_float_dtype(data.dtype):
return Float64Index(data, copy=copy, dtype=dtype, name=name)
elif issubclass(data.dtype.type, np.bool) or is_bool_dtype(data):
elif issubclass(data.dtype.type, bool) or is_bool_dtype(data):
subarr = data.astype("object")
else:
subarr = com.asarray_tuplesafe(data, dtype=object)
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1951,7 +1951,7 @@ def _check_comparison_types(
if isinstance(result, np.ndarray):
# The shape of the mask can differ to that of the result
# since we may compare only a subset of a's or b's elements
tmp = np.zeros(mask.shape, dtype=np.bool)
tmp = np.zeros(mask.shape, dtype=np.bool_)
tmp[mask] = result
result = tmp

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/util/hashing.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def hash_array(

# First, turn whatever array this is into unsigned 64-bit ints, if we can
# manage it.
elif isinstance(dtype, np.bool):
elif isinstance(dtype, bool):
vals = vals.astype("u8")
elif issubclass(dtype.type, (np.datetime64, np.timedelta64)):
vals = vals.view("i8").astype("u8", copy=False)
Expand Down
6 changes: 3 additions & 3 deletions pandas/io/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3476,13 +3476,13 @@ def _get_empty_meta(columns, index_col, index_names, dtype=None):
# This will enable us to write `dtype[col_name]`
# without worrying about KeyError issues later on.
if not isinstance(dtype, dict):
# if dtype == None, default will be np.object.
default_dtype = dtype or np.object
# if dtype == None, default will be object.
default_dtype = dtype or object
dtype = defaultdict(lambda: default_dtype)
else:
# Save a copy of the dictionary.
_dtype = dtype.copy()
dtype = defaultdict(lambda: np.object)
dtype = defaultdict(lambda: object)

# Convert column indexes to column names.
for k, v in _dtype.items():
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/sas/sas7bdat.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ def read(self, nrows=None):
nd = self._column_types.count(b"d")
ns = self._column_types.count(b"s")

self._string_chunk = np.empty((ns, nrows), dtype=np.object)
self._string_chunk = np.empty((ns, nrows), dtype=object)
self._byte_chunk = np.zeros((nd, 8 * nrows), dtype=np.uint8)

self._current_row_in_chunk_index = 0
Expand Down
8 changes: 4 additions & 4 deletions pandas/io/stata.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def convert_delta_safe(base, deltas, unit) -> Series:
elif fmt.startswith(("%tC", "tC")):

warnings.warn("Encountered %tC format. Leaving in Stata Internal Format.")
conv_dates = Series(dates, dtype=np.object)
conv_dates = Series(dates, dtype=object)
if has_bad_values:
conv_dates[bad_locs] = NaT
return conv_dates
Expand Down Expand Up @@ -451,7 +451,7 @@ def g(x: datetime.datetime) -> int:
conv_dates = 4 * (d.year - stata_epoch.year) + (d.month - 1) // 3
elif fmt in ["%th", "th"]:
d = parse_dates_safe(dates, year=True)
conv_dates = 2 * (d.year - stata_epoch.year) + (d.month > 6).astype(np.int)
conv_dates = 2 * (d.year - stata_epoch.year) + (d.month > 6).astype(int)
elif fmt in ["%ty", "ty"]:
d = parse_dates_safe(dates, year=True)
conv_dates = d.year
Expand Down Expand Up @@ -553,7 +553,7 @@ def _cast_to_stata_types(data: DataFrame) -> DataFrame:
ws = ""
# original, if small, if large
conversion_data = (
(np.bool, np.int8, np.int8),
(np.bool_, np.int8, np.int8),
(np.uint8, np.int8, np.int16),
(np.uint16, np.int16, np.int32),
(np.uint32, np.int32, np.int64),
Expand Down Expand Up @@ -1725,7 +1725,7 @@ def _do_convert_missing(self, data: DataFrame, convert_missing: bool) -> DataFra
if convert_missing: # Replacement follows Stata notation
missing_loc = np.nonzero(np.asarray(missing))[0]
umissing, umissing_loc = np.unique(series[missing], return_inverse=True)
replacement = Series(series, dtype=np.object)
replacement = Series(series, dtype=object)
for j, um in enumerate(umissing):
missing_value = StataMissingValue(um)

Expand Down
2 changes: 1 addition & 1 deletion pandas/plotting/_matplotlib/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def _handle_shared_axes(axarr, nplots, naxes, nrows, ncols, sharex, sharey):
try:
# first find out the ax layout,
# so that we can correctly handle 'gaps"
layout = np.zeros((nrows + 1, ncols + 1), dtype=np.bool)
layout = np.zeros((nrows + 1, ncols + 1), dtype=np.bool_)
for ax in axarr:
layout[row_num(ax), col_num(ax)] = ax.get_visible()

Expand Down
Loading

0 comments on commit 72aed3e

Please sign in to comment.