Skip to content

add constant time Series/Dataframe.count(), trivial implementations of iloc(integer) #176

Open

Description

@nevion

count requires O(N) and at(offset) - the most frequent type of index - does hashmap lookups.

consider an O(N) for loop becomes O(N^2) and the performance of this sort of loop could have.... The random places in practice one needs the shape of a dataframe are high and shouldn't incur computation or heavy operations.

function visitEveryRow( visitor )
for(let i = 0; i < df.count(); ++i){
   visitor(df.iloc[i])
}

Activity

  1. changed the title [-]add constant time Series/Dataframe.count(), trivial implementations of iat(integer)[/-] [+]add constant time Series/Dataframe.count(), trivial implementations of iloc(integer)[/+] on Dec 26, 2024
  2. ashleydavis commented on Dec 29, 2024

    @ashleydavis
    Member

    @nevion thanks for you feedback. Are you able to propose a solution?

  3. nevion commented on Dec 29, 2024

    @nevion
    Author

    return this.getContent().values.length, similiar for Series.

    iloc(index: number) : this.getContent().values[index]

    also noticed dtypes aren't stored as part of the context - these should be preserved for 0 length data frames

  4. ashleydavis commented on Jan 2, 2025

    @ashleydavis
    Member

    Thanks @nevion, are you up for getting that in a PR?

  5. nevion commented on Jan 2, 2025

    @nevion
    Author

    I think one thing that needs evaluation is remove allowing deferred values for construction which is something for instance pandas doesn't do and which is satisfiable by another strategy which is user holding a promise around a dataframe / using an async expression , not having the dataframe deal with that internally. This would remove the checking for deferred values inside the dataframe and allow the trivial implementations above which optimize out well and simplify + optimize to the common case. Wdyt?

  6. ashleydavis commented on Jan 2, 2025

    @ashleydavis
    Member

    I think it could be a good idea, but I'm worried removing something could break existing code. I suppose you could implement it so that the deferred values are evaluated immediately - would that still result in the desired simplification?

  7. nevion commented on Jan 2, 2025

    @nevion
    Author

    yea I think so, test if it's a generator vs an array and if generator eval in constructor

  8. ashleydavis commented on Jan 2, 2025

    @ashleydavis
    Member

    Sounds like it shouldn't be too hard. Do you want to try it and submit a PR? For the first step (evaluating the lazy argument in the constructor) shouldn't require any new tests... just need to keep existing tests passing and try to make sure the interface to the user is the same.

    No hurry though... take your time with it.

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