Skip to content

BUG: undefined name in grouputils.dummy_sparse #5687

Closed

Description

@jbrockmendel

The content of the function is:

def dummy_sparse(groups):
    from scipy import sparse

    indptr = np.arange(len(groups)+1)
    data = np.ones(len(groups), dtype=np.int8)
    indi = sparse.csr_matrix((data, g, indptr))

    return indi

But the g variable is undefined. I'm pretty sure that should be groups instead of g. @josef-pkt can you confirm this guess? If so, would the example in the docstring make for a valid test case if I push a PR fixing this?

Activity

  1. josef-pkt commented on May 10, 2019

    @josef-pkt
    Member

    This might be obsolete. AFAIR, I had an updated version somewhere in a PR or merged. I'm not sure where. A file search in master does not find any other version.
    (maybe in sparse ols or absorb PRs)

    I'm also pretty sure g should be replaced by groups. examples in docstring looks fine as test case

  2. josef-pkt commented on May 10, 2019

    @josef-pkt
    Member

    original issue #2771

  3. jbrockmendel commented on May 11, 2019

    @jbrockmendel
    ContributorAuthor

    This might be obsolete.

    Do you mean the entire function?

  4. josef-pkt commented on May 11, 2019

    @josef-pkt
    Member

    There is no newer version of the function in master, AFAICS, so the function is not obsolete and should be fixed.

    Whether we add more specific sparse matrix support and where those function will finally end up is a question for future PRs, or future resurrection of old PRs.

  5. jbrockmendel commented on May 14, 2019

    @jbrockmendel
    ContributorAuthor

    It looks like there is a dummy_sparse method in Grouping that is tested. I'd guess that this was intended to replace the dummy_sparse function, except for the fact that the function is still called in one place from within Group.dummy.

    Is it possible that the call to the function in Group.dummy is supposed to be updated to call the (apparently better-maintained) method?

  6. josef-pkt commented on May 14, 2019

    @josef-pkt
    Member

    No, a method in a class is not a substitute for the standalone function.

    Aside: the module reflects the conflict between maintainers at the time.
    There is one version based on numpy and one version based on pandas.
    (It's a bit like summary versus summary2)

    Neither version strictly dominates the other.

  7. jbrockmendel commented on May 14, 2019

    @jbrockmendel
    ContributorAuthor

    No, a method in a class is not a substitute for the standalone function.

    The idea would not be to remove the function altogether, but to have it defer its implementation, e.g.:

    def dummy_sparse(groups):
        grp = Grouping(groups)
        grp.dummy_sparse()
        return grp._dummies
    

    Or for that matter, since the method and the function do use very similar code, the function could be fixed and the method could dispatch to the function.

  8. added 2 commits that reference this issue on May 14, 2019
    8bd37ab
    900b24b
  9. josef-pkt commented on May 14, 2019

    @josef-pkt
    Member

    the function could be fixed and the method could dispatch to the function.

    that's better. Grouping is a detour and designed to use pandas, which I don't want when I have computational code as in my absorb PR (Actually, there I do have a group-demean version that uses pandas because it is more flexible and faster than my numpy version for that case.)

  10. added 3 commits that reference this issue on May 14, 2019
    8127247
    a796a1c
    1317d6b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions