Eliminate FutureWarning: Series.base is deprecated (#4337)
* Remove all references to data.base Should eliminate the deprecation warning in issue #4300 * Fix lint
This commit is contained in:
parent
d9a47794a5
commit
562d9ae963
@ -584,9 +584,7 @@ class DMatrix(object):
|
|||||||
data: numpy array
|
data: numpy array
|
||||||
The array of data to be set
|
The array of data to be set
|
||||||
"""
|
"""
|
||||||
if getattr(data, 'base', None) is not None and \
|
if isinstance(data, np.ndarray):
|
||||||
data.base is not None and isinstance(data, np.ndarray) \
|
|
||||||
and isinstance(data.base, np.ndarray) and (not data.flags.c_contiguous):
|
|
||||||
self.set_float_info_npy2d(field, data)
|
self.set_float_info_npy2d(field, data)
|
||||||
return
|
return
|
||||||
c_data = c_array(ctypes.c_float, data)
|
c_data = c_array(ctypes.c_float, data)
|
||||||
@ -607,13 +605,15 @@ class DMatrix(object):
|
|||||||
data: numpy array
|
data: numpy array
|
||||||
The array of data to be set
|
The array of data to be set
|
||||||
"""
|
"""
|
||||||
if getattr(data, 'base', None) is not None and \
|
try:
|
||||||
data.base is not None and isinstance(data, np.ndarray) \
|
if not data.flags.c_contiguous:
|
||||||
and isinstance(data.base, np.ndarray) and (not data.flags.c_contiguous):
|
warnings.warn("Use subset (sliced data) of np.ndarray is not recommended " +
|
||||||
warnings.warn("Use subset (sliced data) of np.ndarray is not recommended " +
|
"because it will generate extra copies and increase " +
|
||||||
"because it will generate extra copies and increase memory consumption")
|
"memory consumption")
|
||||||
data = np.array(data, copy=True, dtype=np.float32)
|
data = np.array(data, copy=True, dtype=np.float32)
|
||||||
else:
|
else:
|
||||||
|
data = np.array(data, copy=False, dtype=np.float32)
|
||||||
|
except AttributeError:
|
||||||
data = np.array(data, copy=False, dtype=np.float32)
|
data = np.array(data, copy=False, dtype=np.float32)
|
||||||
c_data = data.ctypes.data_as(ctypes.POINTER(ctypes.c_float))
|
c_data = data.ctypes.data_as(ctypes.POINTER(ctypes.c_float))
|
||||||
_check_call(_LIB.XGDMatrixSetFloatInfo(self.handle,
|
_check_call(_LIB.XGDMatrixSetFloatInfo(self.handle,
|
||||||
@ -632,13 +632,15 @@ class DMatrix(object):
|
|||||||
data: numpy array
|
data: numpy array
|
||||||
The array of data to be set
|
The array of data to be set
|
||||||
"""
|
"""
|
||||||
if getattr(data, 'base', None) is not None and \
|
try:
|
||||||
data.base is not None and isinstance(data, np.ndarray) \
|
if not data.flags.c_contiguous:
|
||||||
and isinstance(data.base, np.ndarray) and (not data.flags.c_contiguous):
|
warnings.warn("Use subset (sliced data) of np.ndarray is not recommended " +
|
||||||
warnings.warn("Use subset (sliced data) of np.ndarray is not recommended " +
|
"because it will generate extra copies and increase " +
|
||||||
"because it will generate extra copies and increase memory consumption")
|
"memory consumption")
|
||||||
data = np.array(data, copy=True, dtype=ctypes.c_uint)
|
data = np.array(data, copy=True, dtype=ctypes.c_uint)
|
||||||
else:
|
else:
|
||||||
|
data = np.array(data, copy=False, dtype=ctypes.c_uint)
|
||||||
|
except AttributeError:
|
||||||
data = np.array(data, copy=False, dtype=ctypes.c_uint)
|
data = np.array(data, copy=False, dtype=ctypes.c_uint)
|
||||||
_check_call(_LIB.XGDMatrixSetUIntInfo(self.handle,
|
_check_call(_LIB.XGDMatrixSetUIntInfo(self.handle,
|
||||||
c_str(field),
|
c_str(field),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user