Skip to content
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

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

Open
NauelSerraino opened this issue Jul 16, 2024 · 0 comments

Comments

@NauelSerraino
Copy link

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.

@NauelSerraino NauelSerraino changed the title panel_structure_stats() returns a generic numpy error if ids are negative panel_structure_stats() returns a generic numpy error if ids are negative Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant