Unverified Commit 3eb68e85 authored by Madnex's avatar Madnex Committed by GitHub
Browse files

[python-package] prefix is_numpy_1d_array with _ (#5520)

parent 22301342
...@@ -177,7 +177,7 @@ def _is_numeric(obj: Any) -> bool: ...@@ -177,7 +177,7 @@ def _is_numeric(obj: Any) -> bool:
return False return False
def is_numpy_1d_array(data: Any) -> bool: def _is_numpy_1d_array(data: Any) -> bool:
"""Check whether data is a numpy 1-D array.""" """Check whether data is a numpy 1-D array."""
return isinstance(data, np.ndarray) and len(data.shape) == 1 return isinstance(data, np.ndarray) and len(data.shape) == 1
...@@ -205,7 +205,7 @@ def is_1d_list(data: Any) -> bool: ...@@ -205,7 +205,7 @@ def is_1d_list(data: Any) -> bool:
def _is_1d_collection(data: Any) -> bool: def _is_1d_collection(data: Any) -> bool:
"""Check whether data is a 1-D collection.""" """Check whether data is a 1-D collection."""
return ( return (
is_numpy_1d_array(data) _is_numpy_1d_array(data)
or is_numpy_column_array(data) or is_numpy_column_array(data)
or is_1d_list(data) or is_1d_list(data)
or isinstance(data, pd_Series) or isinstance(data, pd_Series)
...@@ -214,7 +214,7 @@ def _is_1d_collection(data: Any) -> bool: ...@@ -214,7 +214,7 @@ def _is_1d_collection(data: Any) -> bool:
def list_to_1d_numpy(data, dtype=np.float32, name='list'): def list_to_1d_numpy(data, dtype=np.float32, name='list'):
"""Convert data to numpy 1-D array.""" """Convert data to numpy 1-D array."""
if is_numpy_1d_array(data): if _is_numpy_1d_array(data):
return cast_numpy_array_to_dtype(data, dtype) return cast_numpy_array_to_dtype(data, dtype)
elif is_numpy_column_array(data): elif is_numpy_column_array(data):
_log_warning('Converting column-vector to 1d array') _log_warning('Converting column-vector to 1d array')
...@@ -320,7 +320,7 @@ def param_dict_to_str(data: Optional[Dict[str, Any]]) -> str: ...@@ -320,7 +320,7 @@ def param_dict_to_str(data: Optional[Dict[str, Any]]) -> str:
return "" return ""
pairs = [] pairs = []
for key, val in data.items(): for key, val in data.items():
if isinstance(val, (list, tuple, set)) or is_numpy_1d_array(val): if isinstance(val, (list, tuple, set)) or _is_numpy_1d_array(val):
def to_string(x): def to_string(x):
if isinstance(x, list): if isinstance(x, list):
return f"[{','.join(map(str, x))}]" return f"[{','.join(map(str, x))}]"
...@@ -515,7 +515,7 @@ def c_float_array(data): ...@@ -515,7 +515,7 @@ def c_float_array(data):
"""Get pointer of float numpy array / list.""" """Get pointer of float numpy array / list."""
if is_1d_list(data): if is_1d_list(data):
data = np.array(data, copy=False) data = np.array(data, copy=False)
if is_numpy_1d_array(data): if _is_numpy_1d_array(data):
data = convert_from_sliced_object(data) data = convert_from_sliced_object(data)
assert data.flags.c_contiguous assert data.flags.c_contiguous
if data.dtype == np.float32: if data.dtype == np.float32:
...@@ -535,7 +535,7 @@ def c_int_array(data): ...@@ -535,7 +535,7 @@ def c_int_array(data):
"""Get pointer of int numpy array / list.""" """Get pointer of int numpy array / list."""
if is_1d_list(data): if is_1d_list(data):
data = np.array(data, copy=False) data = np.array(data, copy=False)
if is_numpy_1d_array(data): if _is_numpy_1d_array(data):
data = convert_from_sliced_object(data) data = convert_from_sliced_object(data)
assert data.flags.c_contiguous assert data.flags.c_contiguous
if data.dtype == np.int32: if data.dtype == np.int32:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment