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

weightstats quantile error with len 1 array #7046

Closed
brl0 opened this issue Sep 19, 2020 · 2 comments
Closed

weightstats quantile error with len 1 array #7046

brl0 opened this issue Sep 19, 2020 · 2 comments

Comments

@brl0
Copy link
Contributor

brl0 commented Sep 19, 2020

Describe the bug

DescrStatsW.quantile throws an error when the inputs contain one element.
TypeError: len() of unsized object

This seems to happen because the weights array is squeezed to a zero-dimensional scalar when it contains only a single value.

This occurred while I was performing a groupby/apply operation on a pandas dataframe in which the groups may contain one or more rows.

I will submit a PR with a fix and a simple test for the issue.

Code Sample, a copy-pastable example if possible

from statsmodels.stats.weightstats import DescrStatsW
x1 = [1]
w1 = [1]
d1 = DescrStatsW(x1, w1)
assert (d1.quantile([0.0, 0.5, 1.0]) == 1).all()

Note: As you can see, there are many issues on our GitHub tracker, so it is very possible that your issue has been posted before. Please check first before submitting so that we do not have to handle and close duplicates.

Note: Please be sure you are using the latest released version of statsmodels, or a recent build of master. If your problem has been fixed in an unreleased version, you might be able to use master until a new release occurs.

Note: If you are using a released version, have you verified that the bug exists in the master branch of this repository? It helps the limited resources if we know problems exist in the current master so that they do not need to check whether the code sample produces a bug in the next release.

If the issue has not been resolved, please file it in the issue tracker.

Expected Output

A clear and concise description of what you expected to happen.

Output of import statsmodels.api as sm; sm.show_versions()

[paste the output of import statsmodels.api as sm; sm.show_versions() here below this line]
ImportError: cannot import name '_initialization' from 'statsmodels.tsa.statespace' (/home/brl0/repos/statsmodels/statsmodels/tsa/statespace/__init__.py)

@josef-pkt
Copy link
Member

duplicate of #4282

but we leave it open to fix this soon

@josef-pkt
Copy link
Member

fixed in #7230 which is rebased #7047

@bashtage bashtage added this to the 0.12 milestone Jan 27, 2021
@bashtage bashtage modified the milestones: 0.12, 0.13 Sep 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants