Skip to content

numpy is imported unconditionally #5729

Closed

Description

@crusaderky

We have many unit tests that generate Nannies with spawn method. In theory, those tests should become a lot faster if numpy was imported only if needed.
This is not the case today, because of

  1. two places that import pandas; see blockers:
  2. two import blosc statements in distributed.protocol.compression

xfailed unit test is already in #5695.

Note that this means that fixing this issue means that, across all unit tests that do use numpy data on nannies, import numpy will be moved from @gen_cluster start to the first time where a numpy array or function is deserialised - which in turn may cause flakiness if the test time margins are too tight.

CC @gjoseph92

Activity

  1. gjoseph92 commented on Jan 28, 2022

    @gjoseph92
    Collaborator

    Yes, I also just looked into the same thing. Maybe we should provide a helper in #5724 for checking if a package exists (via importlib.metadata/pkg_resources) without actually importing it, so we can use that on blosc?
    Also xref #5269.

  2. crusaderky commented on Jan 28, 2022

    @crusaderky
    CollaboratorAuthor

    Maybe we should provide a helper in #5724 for checking if a package exists (via importlib.metadata/pkg_resources) without actually importing it, so we can use that on blosc?

    Not that simple - distributed.protocol.compression fills up a dict of compress/decompress callables at module import time, so we'd need to be a bit more creative.

  3. gjoseph92 commented on Jan 28, 2022

    @gjoseph92
    Collaborator

    Blosc/python-blosc#159 seems stalled, but we could probably suggest just not importing the tests in top-level __init__.py. I'm not sure this is worth worrying about too much right now beyond trying to get an upstream change?

  4. crusaderky commented on Feb 24, 2022

    @crusaderky
    CollaboratorAuthor

    WON'T FIX

    #5750 introduces a new unconditional import of numpy, whose benefits definitely exceed those of this ticket.

  5. jakirkham commented on Feb 24, 2022

    @jakirkham
    Member

    If you can think of better ways to handle that import, am open to other options 🙂

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