Skip to content

What do we export? #174

Closed
Closed

Description

@ivirshup

I just found out that batchglm expects to be able to import anndata.base.Raw, which is an issue for upcoming releases on anndata.

What should we export from where in v0.7? My instinct is that any class a user could come in contact with should be exported at a relatively shallow depth. I'm thinking the main anndata namespace could be a good option.

Advantages:

  • No reliance on module structure for the rest of the code
  • Cleaner import syntax
from Module import Class1, Class2, func1, func2
# vs
from Module import func1, func2
from Module.core.submodule import Class1, Class2

Disadvantages:

  • Requires modules defining these objects to be imported, possibly leading to slow overall import times
  • Potentially cluttered main namespace
  • I feel like main-namespace can be a strong API commitment

Activity

  1. falexwolf commented on Jul 4, 2019

    @falexwolf
    Member

    I think that any class or function from a private submodule that a user gets in contact with should be exported in the main namespace. I think, .core should be private and hence better named ._core.

    We can simply point @davidsebfischer to the fact that anndata.base.Raw will be gone from that location. anndata.base was never meant as a user module, and it should have been prefixed by an underscore anndata._base, but I wasn't that aware of these issues at the time and never renamed it in order to maintain backwards compat. As we're breaking it now, anyway, it would be a good time to also go for ._core.

    What do you think?

  2. ivirshup commented on Jul 5, 2019

    @ivirshup
    MemberAuthor

    I agree get the reasoning behind naming it ._core but I'd have to think about why others use .core (xarray, pandas, dask (also has base), and zarr). Possibly due to PEP8 conventions?

    I think it's also fair to say undocumented stuff has no guarantees. Raw was documented, so it's reasonable to rely on it. (update: maybe not)

  3. falexwolf commented on Jul 5, 2019

    @falexwolf
    Member

    I think that recently, quite a few packages went away from a ton of public modules (like .core), with no real public use, to having dedicated private modules like ._core. I think that in Scanpy, it made a lot of sense. Some while ago, @flying-sheep also shared the API design of a package he liked a lot; and they also went down this road. But I don't remember the name.

  4. falexwolf commented on Jul 5, 2019

    @falexwolf
    Member

    So, to answer your question more directly: Maybe they have it for backward compat reasons as well. It just doesn't make sense to have a non-user module in the high-level lookup menus, in my opinion. The lookup should direct the user to the functions and classes he/she needs.
    image

  5. added a commit that references this issue on Jul 6, 2019
  6. davidsebfischer commented on Jul 8, 2019

    @davidsebfischer

    I'll adapt this in any way necessary, just do whatever is best for you! I just needed this for typing. I think it relevant for related packages to distinguish between the full anndata and the raw objects through isinstance() calls though? So exposing the class in some way would be crucial.

    This import in batchglm is hidden from the user and I'll switch the scanpy version dependency accordingly once you made this change! So do not worry too much about backwards compatibility for batchglm.

  7. davidsebfischer commented on Jul 30, 2019

    @davidsebfischer

    I added a conditional import of this object in v0.6.1, so diffxpy and batchglm can handle both the old and new interface to the location of anndata raw objects now.

  8. pinned this issue on Aug 23, 2019
  9. flying-sheep commented on Aug 23, 2019

    @flying-sheep
    Member

    Currently the classes that appear in function/property type hints are:

    • anndata.core.anndata.Raw (AnnData.raw)
    • anndata.core.views.ArrayView (AnnData.X)
    • anndata.core.alignedmapping.LayersBase (AnnData.layers)
    • anndata.core.alignedmapping.AxisArraysBase (AnnData.obsm, AnnData.varm)
    • anndata.core.alignedmapping.PairwiseArraysBase (AnnData.obsp, AnnData.varp)

    We need to decide which of them to export/document and which where we simply want to replace the type hints with some annotation, like LayersBase → MutableMapping[Union[ndarray, csr_matrix]]

    I’m thinking that we should export and document them all. Raw is its own beast and should be documented separately from the rest, and we should create a little section introducing all copy-on-write classes.

    They all need to be renamed. We don’t want to expose the internals, just the final classes, so ArrayView→COWMatrix, LayersBase→Layers, AxisArraysBase→AlignedMatrices, and PairwiseArraysBase→SquareMatrices or so.

  10. jorvis commented on Jun 15, 2020

    @jorvis

    I ran into this issue too when upgrading to the latest anndata. Previously, if someone sends a file with input columns 'tSNE_1' and 'tSNE_2' I'd transform these into a saved analysis like this:

    adata.obsm['X_tsne'] = ad.base.BoundRecArr(input_array=adata.obs[['tSNE_1', 'tSNE_2']].values, parent=adata, attr='obsm')
    

    This now fails though because 'base' is no longer public. I'd happily take advice on a cleaner way to do this.

    Edit: Well, it looks like it's just far simpler now. Just a simple array().

    adata.obsm['X_tsne'] = adata.obs[['tSNE_1', 'tSNE_2']].values
    
  11. unpinned this issue on Jun 15, 2023
  12. github-actions commented on Jul 13, 2023

    @github-actions

    This issue has been automatically marked as stale because it has not had recent activity.
    Please add a comment if you want to keep the issue open. Thank you for your contributions!

  13. flying-sheep commented on Jul 13, 2023

    @flying-sheep
    Member

    this is now under control

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions