Skip to content

weightstats quantile error with len 1 array #7046

Closed

Description

@brl0

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()
Details

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()

Details

[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)

Activity

  1. josef-pkt commented on Sep 19, 2020

    @josef-pkt
    Member

    duplicate of #4282

    but we leave it open to fix this soon

  2. josef-pkt commented on Jan 21, 2021

    @josef-pkt
    Member

    fixed in #7230 which is rebased #7047

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions