Skip to content

panel_structure_stats() returns a generic numpy error if ids are negative #614

@NauelSerraino

Description

@NauelSerraino

The function np.bincount(ids) returns a generic ValueError: 'list' argument must have no negative elements.

def panel_structure_stats(ids: IntArray, name: str) -> Series:
bc = np.bincount(ids)
bc = bc[bc > 0]
index = ["mean", "median", "max", "min", "total"]
out = [bc.mean(), np.median(bc), bc.max(), bc.min(), bc.shape[0]]
return Series(out, index=index, name=name)

In my case that happened due to some NaN within the entity effect, which lead to negative values (-1) in the ids.

In my opinion, both the properties entity_ids and time_ids should return an error if the elements in the index contains some NaN (since I had a quite hard time figuring it out).

@property
def entity_ids(self) -> IntArray:
"""
Get array containing entity group membership information
Returns
-------
ndarray
2d array containing entity ids corresponding dataframe view
"""
index = self.index
return np.asarray(index.codes[0])[:, None]
@property
def time_ids(self) -> IntArray:
"""
Get array containing time membership information
Returns
-------
ndarray
2d array containing time ids corresponding dataframe view
"""
index = self.index
return np.asarray(index.codes[1])[:, None]

If necessary, I would be happy to work on that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions