Skip to content

Commit

Permalink
Remove warnings (#91)
Browse files Browse the repository at this point in the history
* replaced np.float with float

* updated version

* replaced np.int with int
  • Loading branch information
tommyod committed May 11, 2021
1 parent 126365b commit c36751e
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion KDEpy/BaseKDE.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def _process_sequence(sequence_array_like):
raise ValueError("Must be of shape (obs, dims)")
else:
raise TypeError("Must be of shape (obs, dims)")
return np.asarray_chkfinite(out, dtype=np.float)
return np.asarray_chkfinite(out, dtype=float)

def _evalate_return_logic(self, evaluated, grid_points):
"""
Expand Down
2 changes: 1 addition & 1 deletion KDEpy/TreeKDE.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def evaluate(self, grid_points=None, eps=10e-4):
if isinstance(bw, numbers.Number):
bw = np.asfarray(np.ones(obs) * bw)
else:
bw = np.asarray_chkfinite(bw, dtype=np.float)
bw = np.asarray_chkfinite(bw, dtype=float)

# Initialize the tree structure for fast lookups of neighbors
tree = cKDTree(self.data)
Expand Down
2 changes: 1 addition & 1 deletion KDEpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from KDEpy.TreeKDE import TreeKDE
from KDEpy.FFTKDE import FFTKDE

__version__ = "1.0.10"
__version__ = "1.0.11"
__author__ = "tommyod"

TreeKDE = TreeKDE
Expand Down
40 changes: 20 additions & 20 deletions KDEpy/binning.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ def linbin_cython(data, grid_points, weights=None):
True
"""
# Convert the data and grid points
data = np.asarray_chkfinite(data, dtype=np.float)
grid_points = np.asarray_chkfinite(grid_points, dtype=np.float)
data = np.asarray_chkfinite(data, dtype=float)
grid_points = np.asarray_chkfinite(grid_points, dtype=float)

assert len(data.shape) == 1
assert len(grid_points.shape) == 1
Expand All @@ -88,7 +88,7 @@ def linbin_cython(data, grid_points, weights=None):

if weights is not None:
assert len(weights.shape) == 1
weights = np.asarray_chkfinite(weights, dtype=np.float)
weights = np.asarray_chkfinite(weights, dtype=float)
weights = weights / np.sum(weights)

if (weights is not None) and (len(data) != len(weights)):
Expand Down Expand Up @@ -146,8 +146,8 @@ def linbin_numpy(data, grid_points, weights=None):
True
"""
# Convert the data and grid points
data = np.asarray_chkfinite(data, dtype=np.float)
grid_points = np.asarray_chkfinite(grid_points, dtype=np.float)
data = np.asarray_chkfinite(data, dtype=float)
grid_points = np.asarray_chkfinite(grid_points, dtype=float)
assert len(data.shape) == 1
assert len(grid_points.shape) == 1

Expand All @@ -158,7 +158,7 @@ def linbin_numpy(data, grid_points, weights=None):
if weights is None:
weights = np.ones_like(data)

weights = np.asarray_chkfinite(weights, dtype=np.float)
weights = np.asarray_chkfinite(weights, dtype=float)
weights = weights / np.sum(weights)

if not len(data) == len(weights):
Expand All @@ -175,7 +175,7 @@ def linbin_numpy(data, grid_points, weights=None):
# The integral part is used for lookups, the fractional part is used
# to weight the data
fractional, integral = np.modf(transformed_data)
integral = integral.astype(np.int)
integral = integral.astype(int)

# Sort the integral values, and the fractional data and weights by
# the same key. This lets us use binary search, which is faster
Expand Down Expand Up @@ -233,10 +233,10 @@ def linbin_Ndim_python(data, grid_points, weights=None):
>>> d = linbin_Ndim_python(np.array([[1.0, 0, 0]]), grid_points, None)
"""
# Convert the data and grid points
data = np.asarray_chkfinite(data, dtype=np.float)
grid_points = np.asarray_chkfinite(grid_points, dtype=np.float)
data = np.asarray_chkfinite(data, dtype=float)
grid_points = np.asarray_chkfinite(grid_points, dtype=float)
if weights is not None:
weights = np.asarray_chkfinite(weights, dtype=np.float)
weights = np.asarray_chkfinite(weights, dtype=float)
else:
# This is not efficient, but this function should just be correct
# The faster algorithm is implemented in Cython
Expand All @@ -260,7 +260,7 @@ def linbin_Ndim_python(data, grid_points, weights=None):
data = (data - min_grid) / dx

# Create results
result = np.zeros(grid_points.shape[0], dtype=np.float)
result = np.zeros(grid_points.shape[0], dtype=float)

# Go through every data point
for observation, weight in zip(data, weights):
Expand Down Expand Up @@ -324,10 +324,10 @@ def linbin_Ndim(data, grid_points, weights=None):
assert data_dims >= 2

# Convert the data and grid points
data = np.asarray_chkfinite(data, dtype=np.float)
grid_points = np.asarray_chkfinite(grid_points, dtype=np.float)
data = np.asarray_chkfinite(data, dtype=float)
grid_points = np.asarray_chkfinite(grid_points, dtype=float)
if weights is not None:
weights = np.asarray_chkfinite(weights, dtype=np.float)
weights = np.asarray_chkfinite(weights, dtype=float)
weights = weights / np.sum(weights)

if (weights is not None) and (data.shape[0] != len(weights)):
Expand All @@ -347,7 +347,7 @@ def linbin_Ndim(data, grid_points, weights=None):
data = (data - min_grid) / dx

# Create results
result = np.zeros(grid_points.shape[0], dtype=np.float)
result = np.zeros(grid_points.shape[0], dtype=float)

# Call the Cython implementation. Loops are unrolled if d=1 or d=2,
# and if d >= 3 a more general routine is called. It's a bit slower since
Expand All @@ -360,7 +360,7 @@ def linbin_Ndim(data, grid_points, weights=None):
result = cutils.iterate_data_ND_weighted(data, weights, result, grid_num, obs_tot, binary_flgs)
else:
result = cutils.iterate_data_2D_weighted(data, weights, result, grid_num, obs_tot)
result = np.asarray_chkfinite(result, dtype=np.float)
result = np.asarray_chkfinite(result, dtype=float)

# Unweighted data has two specific routines too. This is because creating
# uniform weights takes relatively long time. It's faster to have a
Expand All @@ -371,7 +371,7 @@ def linbin_Ndim(data, grid_points, weights=None):
result = cutils.iterate_data_ND(data, result, grid_num, obs_tot, binary_flgs)
else:
result = cutils.iterate_data_2D(data, result, grid_num, obs_tot)
result = np.asarray_chkfinite(result, dtype=np.float)
result = np.asarray_chkfinite(result, dtype=float)
result = result / data_obs

assert np.allclose(np.sum(result), 1)
Expand Down Expand Up @@ -410,10 +410,10 @@ def linear_binning(data, grid_points, weights=None):
>>> np.allclose(data, np.array([0.33333, 0.36667, 0.3]))
True
"""
data = np.asarray_chkfinite(data, dtype=np.float)
grid_points = np.asarray_chkfinite(grid_points, dtype=np.float)
data = np.asarray_chkfinite(data, dtype=float)
grid_points = np.asarray_chkfinite(grid_points, dtype=float)
if weights is not None:
weights = np.asarray_chkfinite(weights, dtype=np.float)
weights = np.asarray_chkfinite(weights, dtype=float)

# Make sure the dimensionality makes sense
try:
Expand Down
2 changes: 1 addition & 1 deletion KDEpy/bw_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def improved_sheather_jones(data, weights=None):

# Smooth the initial data using the computed optimal t
# Multiplication in frequency domain is convolution
# integers = np.arange(n, dtype=np.float)
# integers = np.arange(n, dtype=float)
# a_t = a * np.exp(-integers**2 * np.pi ** 2 * t_star / 2)

# Diving by 2 done because of the implementation of fftpack.idct
Expand Down
8 changes: 4 additions & 4 deletions KDEpy/tests/test_binning.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ def naivebinning(data, grid_points, weights=None):
"""

# Convert the data to numpy Arrays
data = np.asarray_chkfinite(data, dtype=np.float)
grid_points = np.asarray_chkfinite(grid_points, dtype=np.float)
data = np.asarray_chkfinite(data, dtype=float)
grid_points = np.asarray_chkfinite(grid_points, dtype=float)

if weights is None:
weights = np.ones_like(data)

weights = np.asarray_chkfinite(weights, dtype=np.float)
weights = np.asarray_chkfinite(weights, dtype=float)
weights = weights / np.sum(weights)

# Prepare to transform data
Expand All @@ -48,7 +48,7 @@ def naivebinning(data, grid_points, weights=None):
max_grid = np.max(grid_points)
transformed_data = (data - min_grid) / (max_grid - min_grid) * n

result = np.zeros_like(grid_points, dtype=np.float)
result = np.zeros_like(grid_points, dtype=float)

# Go through data points and weights, use O(1) lookups and weight the
# data point linearily by distance and the perscribed weights
Expand Down

0 comments on commit c36751e

Please sign in to comment.