Skip to content

Commit

Permalink
Do not use warnings from numpy (#1176)
Browse files Browse the repository at this point in the history
numpy has removed the warnings symbol from the __init__.py file so
np.warnings is not valid in newer versions of numpy. This patch justs
imports the warnings module and use it directly.
  • Loading branch information
danigm authored Feb 8, 2023
1 parent 21a8614 commit d8167b4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 3 additions & 3 deletions datashader/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from numbers import Number
from math import log10
import warnings

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -424,7 +425,6 @@ def line(self, source, x=None, y=None, agg=None, axis=0, geometry=None,

if (line_width > 0 and ((cudf and isinstance(source, cudf.DataFrame)) or
(dask_cudf and isinstance(source, dask_cudf.DataFrame)))):
import warnings
warnings.warn(
"Antialiased lines are not supported for CUDA-backed sources, "
"so reverting to line_width=0")
Expand Down Expand Up @@ -1255,8 +1255,8 @@ def bypixel(source, canvas, glyph, agg, *, antialias=False):
canvas.validate()

# All-NaN objects (e.g. chunks of arrays with no data) are valid in Datashader
with np.warnings.catch_warnings():
np.warnings.filterwarnings('ignore', r'All-NaN (slice|axis) encountered')
with warnings.catch_warnings():
warnings.filterwarnings('ignore', r'All-NaN (slice|axis) encountered')
return bypixel.pipeline(source, schema, canvas, glyph, agg, antialias=antialias)


Expand Down
6 changes: 4 additions & 2 deletions datashader/transfer_functions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from collections import OrderedDict
from io import BytesIO

import warnings

import numpy as np
import numba as nb
import toolz as tz
Expand Down Expand Up @@ -457,8 +459,8 @@ def _interpolate_alpha(data, total, mask, how, alpha, span, min_alpha, rescale_d
a_scaled, discrete_levels = a_scaled

# All-NaN objects (e.g. chunks of arrays with no data) are valid in Datashader
with np.warnings.catch_warnings():
np.warnings.filterwarnings('ignore', r'All-NaN (slice|axis) encountered')
with warnings.catch_warnings():
warnings.filterwarnings('ignore', r'All-NaN (slice|axis) encountered')
norm_span = [np.nanmin(a_scaled).item(), np.nanmax(a_scaled).item()]

if rescale_discrete_levels and discrete_levels is not None: # Only valid for how='eq_hist'
Expand Down

0 comments on commit d8167b4

Please sign in to comment.