Skip to content

BUG: numpy 2.0 breaking import #173

Closed

Description

@ralphpeterson

fixed by downgrading numpy: pip install numpy==1.24.0

looks like it's probably not a vocalpy issue, but some versioning issues with its dependencies


AttributeError Traceback (most recent call last)
Cell In[2], line 2
1 from vocalpy.feature.sat import *
----> 2 import vocalpy.spectral
3 from vocalpy import feature
4 from vocalpy import Sound

File ~/anaconda3/envs/vocalpy/lib/python3.10/site-packages/vocalpy/init.py:2
1 """A core package for acoustic communication research in Python."""
----> 2 from . import _vendor, constants, examples, feature, metrics, paths, plot, segment, signal, spectral, validators
3 from .about import (
4 author,
5 commit,
(...)
12 version,
13 )
14 from ._spectrogram.data_type import Spectrogram

File ~/anaconda3/envs/vocalpy/lib/python3.10/site-packages/vocalpy/plot/init.py:10
1 """Module for plotting and visualizations.
2
3 .. autosummary::
(...)
8 spectrogram
9 """
---> 10 from .annot import annotation
11 from .spect import annotated_spectrogram, spectrogram
13 all = [
14 "annotated_spectrogram",
15 "annotation",
16 "spectrogram",
17 ]

File ~/anaconda3/envs/vocalpy/lib/python3.10/site-packages/vocalpy/plot/annot.py:7
4 import matplotlib.pyplot as plt
5 import numpy.typing as npt
----> 7 from ..annotation import Annotation
10 def labels(
11 labels: npt.ArrayLike,
12 t: npt.NDArray,
(...)
16 text_kwargs: dict | None = None,
17 ):
18 """Plot labels of segments on an axis.
19
20 Parameters
(...)
41 of text objections, the matplotlib.Text instances for each label
42 """

File ~/anaconda3/envs/vocalpy/lib/python3.10/site-packages/vocalpy/annotation.py:7
4 import pathlib
6 import attrs
----> 7 import crowsetta
10 @attrs.define
11 class Annotation:
12 """Class that represents annotation data.
13
14 Attributes
(...)
17 path : pathlib.Path
18 """

File ~/anaconda3/envs/vocalpy/lib/python3.10/site-packages/crowsetta/init.py:21
17 from .transcriber import Transcriber
19 # Need to import formats last to avoid circular import errors
20 # isort: off
---> 21 from . import formats
22 from .formats import register_format
24 # isort: on

File ~/anaconda3/envs/vocalpy/lib/python3.10/site-packages/crowsetta/formats/init.py:7
4 from typing import Type
6 from .. import interface
----> 7 from . import bbox, seq
9 FORMATS = {}
10 for module in (bbox, seq):

File ~/anaconda3/envs/vocalpy/lib/python3.10/site-packages/crowsetta/formats/bbox/init.py:1
----> 1 from .audbbox import AudBBox
2 from .raven import Raven
4 all = [
5 "AudBBox",
6 "Raven",
7 ]

File ~/anaconda3/envs/vocalpy/lib/python3.10/site-packages/crowsetta/formats/bbox/audbbox.py:12
10 import attr
11 import pandas as pd
---> 12 import pandera
13 from pandera.typing import Series
15 import crowsetta

File ~/anaconda3/envs/vocalpy/lib/python3.10/site-packages/pandera/init.py:5
1 """A flexible and expressive pandas validation library."""
3 import platform
----> 5 import pandera.backends
6 import pandera.backends.base.builtin_checks
7 import pandera.backends.base.builtin_hypotheses

File ~/anaconda3/envs/vocalpy/lib/python3.10/site-packages/pandera/backends/init.py:4
1 """Pandera backends."""
3 # ensure that base builtin checks and hypothesis are registered
----> 4 import pandera.backends.base.builtin_checks
5 import pandera.backends.base.builtin_hypotheses
6 import pandera.backends.pandas

File ~/anaconda3/envs/vocalpy/lib/python3.10/site-packages/pandera/backends/base/builtin_checks.py:14
11 import re
12 from typing import Any, Iterable, Optional, TypeVar, Union
---> 14 from pandera.api.checks import Check
16 T = TypeVar("T")
19 @Check.register_builtin_check_fn
20 def equal_to(data: Any, value: Any) -> Any:

File ~/anaconda3/envs/vocalpy/lib/python3.10/site-packages/pandera/api/checks.py:17
15 from pandera import errors
16 from pandera.api.base.checks import BaseCheck, CheckResult
---> 17 from pandera.strategies.base_strategies import SearchStrategy
19 T = TypeVar("T")
22 # pylint: disable=too-many-public-methods

File ~/anaconda3/envs/vocalpy/lib/python3.10/site-packages/pandera/strategies/init.py:3
1 """Data synthesis strategies for pandera, powered by the hypothesis package."""
----> 3 from pandera.strategies.pandas_strategies import *

File ~/anaconda3/envs/vocalpy/lib/python3.10/site-packages/pandera/strategies/pandas_strategies.py:42
32 import pandas as pd
34 from pandera.dtypes import (
35 DataType,
36 is_category,
(...)
40 is_timedelta,
41 )
---> 42 from pandera.engines import numpy_engine, pandas_engine
43 from pandera.errors import BaseStrategyOnlyError, SchemaDefinitionError
44 from pandera.strategies.base_strategies import (
45 HAS_HYPOTHESIS,
46 STRATEGY_DISPATCHER,
47 )

File ~/anaconda3/envs/vocalpy/lib/python3.10/site-packages/pandera/engines/pandas_engine.py:757
738 is_python_string = data_container.map(lambda x: isinstance(x, str)) # type: ignore[operator]
739 return is_python_string.astype(bool) | data_container.isna()
742 Engine.register_dtype(
743 numpy_engine.Object,
744 equivalents=[
745 "object",
746 "object_",
747 "object0",
748 "O",
749 "bytes",
750 "mixed-integer",
751 "mixed",
752 "bytes",
753 bytes,
754 object,
755 np.object_,
756 np.bytes_,
--> 757 np.string_,
758 ],
759 )
761 # ###############################################################################
762 # # time
763 # ###############################################################################
766 _PandasDatetime = Union[np.datetime64, pd.DatetimeTZDtype]

File ~/anaconda3/envs/vocalpy/lib/python3.10/site-packages/numpy/init.py:397, in getattr(attr)
394 raise AttributeError(former_attrs[attr])
396 if attr in expired_attributes:
--> 397 raise AttributeError(
398 f"np.{attr} was removed in the NumPy 2.0 release. "
399 f"{expired_attributes[attr]}"
400 )
402 if attr == "chararray":
403 warnings.warn(
404 "np.chararray is deprecated and will be removed from "
405 "the main namespace in the future. Use an array with a string "
406 "or bytes dtype instead.", DeprecationWarning, stacklevel=2)

AttributeError: np.string_ was removed in the NumPy 2.0 release. Use np.bytes_ instead.

Activity

  1. ralphpeterson commented on Jun 22, 2024

    @ralphpeterson
    ContributorAuthor

    btw, this was after a fresh install of vocalpy today on mac os. looks like numpy 2.0 was released a few days ago.

  2. NickleDave commented on Jun 27, 2024

    @NickleDave
    Contributor

    Thank you @ralphpeterson for reporting this and including the full traceback.

    I think you are right that the best fix for now is to specify `pip install vocalpy numpy<2.0"

    You are also right that it's not vocalpy itself, but a dependency of crowsetta that's the source of the issue.

    I just did an install of vak and hit some other issues from the same dependency too.
    Will raise an issue on crowsetta and link to this one

  3. NickleDave commented on Jul 2, 2024

    @NickleDave
    Contributor

    I made some progress on this.

    Released a new version of crowsetta (https://github.com/vocalpy/crowsetta/releases/tag/5.0.3) that fixes the errors above

    But: vocalpy depends on librosa, that depends on a python wrapper around soxr that is not yet numpy 2.0 compatible (see librosa/librosa#1831 and dofuuz/python-soxr#28).
    As stated in those issues, compatibility with numpy 2.0 will be addressed in release 0.4.0 of python-soxr and 0.11 / 1.0 of librosa.

    I want to avoid a fix for this like a vocalpy release that puts an upper bound on any dependencies (e.g. numpy < 2.0) because as I understand it this can cause pip's dependency resolver to do weird things.

    So for now the fix is still just to manually specify numpy<2.0 when you install vocalpy

  4. added a commit that references this issue on Jul 3, 2024
    b2e6def
  5. NickleDave commented on Jul 3, 2024

    @NickleDave
    Contributor

    Nvm, I decided based on this blog post from Henry Schreiner that this is actually a valid case to upper bound numpy for now

  6. NickleDave commented on Jul 3, 2024

    @NickleDave
    Contributor

    @ralphpeterson I just released 0.9.4 that should fix this, please do let me know if not. Thanks again for the detailed issue.

    I'm watching the librosa issue where they're tracking numpy 2.0 compatability to know when we can upgrade

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions