Skip to content

Block.shape inconsistencies? #23023

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jbrockmendel opened this issue Oct 7, 2018 · 0 comments
Closed

Block.shape inconsistencies? #23023

jbrockmendel opened this issue Oct 7, 2018 · 0 comments
Labels
Internals Related to non-user accessible pandas implementation

Comments

@jbrockmendel
Copy link
Member

Trying to simplify some things in internals. I expected that it would always be the case that len(block) == block.shape[0], but shape is flipped in a few cases.

class Block:
    def __len__(self):
        return len(self.values)

    @property
    def shape(self):
        return self.values.shape

class NonConsolidatableMixin:
    @property
    def shape(self):
        if self.ndim == 1:
            return (len(self.values)),
        return (len(self.mgr_locs), len(self.values))

class SparseBlock:
    @property
    def shape(self):
        return (len(self.mgr_locs), self.sp_index.length)

    def __len__(self):
        try:
            return self.sp_index.length
        except AttributeError:
            return 0

So for Block len(b) == b.shape[0], 1-dim NonConsolidatable (and ScalarBlock) behave as expected, but 2-dim have len(b) == b.shape[1]. Ditto SparseBlock (a try/except notwithstanding).

What's the internal logic here?

@mroeschke mroeschke added the Internals Related to non-user accessible pandas implementation label Jan 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Internals Related to non-user accessible pandas implementation
Projects
None yet
Development

No branches or pull requests

2 participants