Skip to content

Commit

Permalink
replace numpy aliases with builtin types (#2236)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaozGelbart authored Aug 31, 2020
1 parent d40c0b0 commit 0534e48
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion examples/many_pairwise_correlations.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
corr = d.corr()

# Generate a mask for the upper triangle
mask = np.triu(np.ones_like(corr, dtype=np.bool))
mask = np.triu(np.ones_like(corr, dtype=bool))

# Set up the matplotlib figure
f, ax = plt.subplots(figsize=(11, 9))
Expand Down
8 changes: 4 additions & 4 deletions seaborn/axisgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def __init__(

# Make a boolean mask that is True anywhere there is an NA
# value in one of the faceting variables, but only if dropna is True
none_na = np.zeros(len(data), np.bool)
none_na = np.zeros(len(data), bool)
if dropna:
row_na = none_na if row is None else data[row].isnull()
col_na = none_na if col is None else data[col].isnull()
Expand Down Expand Up @@ -1483,8 +1483,8 @@ def map_diag(self, func, **kwargs):
for ax in diag_axes[1:]:
group.join(ax, diag_axes[0])

self.diag_vars = np.array(diag_vars, np.object)
self.diag_axes = np.array(diag_axes, np.object)
self.diag_vars = np.array(diag_vars, np.object_)
self.diag_axes = np.array(diag_axes, np.object_)

if "hue" not in signature(func).parameters:
return self._map_diag_iter_hue(func, **kwargs)
Expand Down Expand Up @@ -1629,7 +1629,7 @@ def _plot_bivariate_iter_hue(self, x_var, y_var, ax, func, **kwargs):
data_k = hue_grouped.get_group(label_k)
except KeyError:
data_k = pd.DataFrame(columns=axes_vars,
dtype=np.float)
dtype=float)

if self._dropna:
data_k = data_k[axes_vars].dropna()
Expand Down
14 changes: 7 additions & 7 deletions seaborn/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def establish_variables(self, x=None, y=None, hue=None, data=None,

# Convert to a list of arrays, the common representation
iter_data = plot_data.iteritems()
plot_data = [np.asarray(s, np.float) for k, s in iter_data]
plot_data = [np.asarray(s, float) for k, s in iter_data]

# Option 1b:
# The input data is an array or list
Expand Down Expand Up @@ -125,7 +125,7 @@ def establish_variables(self, x=None, y=None, hue=None, data=None,
plot_data = data

# Convert to a list of arrays, the common representation
plot_data = [np.asarray(d, np.float) for d in plot_data]
plot_data = [np.asarray(d, float) for d in plot_data]

# The group names will just be numeric indices
group_names = list(range((len(plot_data))))
Expand Down Expand Up @@ -1058,7 +1058,7 @@ def point_colors(self):
for i, group_data in enumerate(self.plot_data):

# Initialize the array for this group level
group_colors = np.empty(group_data.size, np.int)
group_colors = np.empty(group_data.size, int)
if isinstance(group_data, pd.Series):
group_colors = pd.Series(group_colors, group_data.index)

Expand Down Expand Up @@ -1118,10 +1118,10 @@ def draw_stripplot(self, ax, kws):
if self.plot_hues is None or not self.dodge:

if self.hue_names is None:
hue_mask = np.ones(group_data.size, np.bool)
hue_mask = np.ones(group_data.size, bool)
else:
hue_mask = np.array([h in self.hue_names
for h in self.plot_hues[i]], np.bool)
for h in self.plot_hues[i]], bool)
# Broken on older numpys
# hue_mask = np.in1d(self.plot_hues[i], self.hue_names)

Expand Down Expand Up @@ -1354,10 +1354,10 @@ def draw_swarmplot(self, ax, kws):
width = self.width

if self.hue_names is None:
hue_mask = np.ones(group_data.size, np.bool)
hue_mask = np.ones(group_data.size, bool)
else:
hue_mask = np.array([h in self.hue_names
for h in self.plot_hues[i]], np.bool)
for h in self.plot_hues[i]], bool)
# Broken on older numpys
# hue_mask = np.in1d(self.plot_hues[i], self.hue_names)

Expand Down
2 changes: 1 addition & 1 deletion seaborn/distributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2553,7 +2553,7 @@ def distplot(a=None, bins=None, hist=True, kde=True, rug=False, fit=None,
a = x

# Make a a 1-d float array
a = np.asarray(a, np.float)
a = np.asarray(a, float)
if a.ndim > 1:
a = a.squeeze()

Expand Down
6 changes: 3 additions & 3 deletions seaborn/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def _matrix_mask(data, mask):
"""
if mask is None:
mask = np.zeros(data.shape, np.bool)
mask = np.zeros(data.shape, bool)

if isinstance(mask, np.ndarray):
# For array masks, ensure that shape matches data then convert
Expand All @@ -76,7 +76,7 @@ def _matrix_mask(data, mask):
mask = pd.DataFrame(mask,
index=data.index,
columns=data.columns,
dtype=np.bool)
dtype=bool)

elif isinstance(mask, pd.DataFrame):
# For DataFrame masks, ensure that semantic labels match data
Expand Down Expand Up @@ -196,7 +196,7 @@ def _determine_cmap_params(self, plot_data, vmin, vmax,
"""Use some heuristics to set good defaults for colorbar and range."""

# plot_data is a np.ma.array instance
calc_data = plot_data.astype(np.float).filled(np.nan)
calc_data = plot_data.astype(float).filled(np.nan)
if vmin is None:
if robust:
vmin = np.nanpercentile(calc_data, 2)
Expand Down
2 changes: 1 addition & 1 deletion seaborn/relational.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ def aggregate(self, vals, grouper, units=None):
seed = self.seed

# Define a "null" CI for when we only have one value
null_ci = pd.Series(index=["low", "high"], dtype=np.float)
null_ci = pd.Series(index=["low", "high"], dtype=float)

# Function to bootstrap in the context of a pandas group by
def bootstrapped_cis(vals):
Expand Down
2 changes: 1 addition & 1 deletion seaborn/tests/test_axisgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ def test_hue_kws(self):
def test_dropna(self):

df = self.df.copy()
hasna = pd.Series(np.tile(np.arange(6), 10), dtype=np.float)
hasna = pd.Series(np.tile(np.arange(6), 10), dtype=float)
hasna[hasna == 5] = np.nan
df["hasna"] = hasna
g = ag.FacetGrid(df, dropna=False, row="hasna")
Expand Down
4 changes: 2 additions & 2 deletions seaborn/tests/test_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def test_df_multindex_input(self):
npt.assert_array_equal(p.xticklabels, combined_tick_labels)
nt.assert_equal(p.xlabel, "letter-number")

@pytest.mark.parametrize("dtype", [np.float, np.int64, np.object])
@pytest.mark.parametrize("dtype", [float, np.int64, object])
def test_mask_input(self, dtype):
kws = self.default_kws.copy()

Expand Down Expand Up @@ -443,7 +443,7 @@ def test_mask_validation(self):

def test_missing_data_mask(self):

data = pd.DataFrame(np.arange(4, dtype=np.float).reshape(2, 2))
data = pd.DataFrame(np.arange(4, dtype=float).reshape(2, 2))
data.loc[0, 0] = np.nan
mask = mat._matrix_mask(data, None)
npt.assert_array_equal(mask, [[True, False], [False, False]])
Expand Down

0 comments on commit 0534e48

Please sign in to comment.