diff --git a/pyproject.toml b/pyproject.toml index 90491dc1..be1a08c8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,7 +9,7 @@ description = "A little word cloud generator" readme = { file = "README.md", content-type = "text/markdown" } requires-python = ">=3.9" license = "MIT" -dependencies = ["numpy>=1.19", "pillow", "matplotlib"] +dependencies = ["numpy>=1.19.3", "pillow", "matplotlib"] dynamic = ["version"] [project.urls] diff --git a/requirements.txt b/requirements.txt index b6600922..be377bf5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ matplotlib>=1.5.3 -numpy>=1.6.1 +numpy>1.19.3; python_version >= '3.10' +numpy==1.19.3; python_version == '3.9' pillow -cython \ No newline at end of file +cython diff --git a/wordcloud/wordcloud.py b/wordcloud/wordcloud.py index 6d46e919..59743638 100644 --- a/wordcloud/wordcloud.py +++ b/wordcloud/wordcloud.py @@ -738,14 +738,22 @@ def to_array(self, copy=None): copy : bool If `True`, then the object is copied. If `None` then the object is copied only if needed. For `False` it raises a ValueError if a copy cannot be - avoided. Default: `None`. + avoided. Default: `None`. `copy` is passed directly to `np.asarray` + which is supported on NumPy>=2.0. For older NumPy versions `copy` is + ignored. Returns ------- image : nd-array size (width, height, 3) Word cloud image as numpy matrix. """ - return np.asarray(self.to_image(), copy=copy) + image = self.to_image() + if copy is None: + return np.asarray(image) + try: + return np.asarray(image, copy=copy) + except TypeError: + return np.asarray(image) def __array__(self, copy=None): """Convert to numpy array.