Code Monkey home page Code Monkey logo

Comments (6)

pwwang avatar pwwang commented on August 11, 2024 1

Closing this as datar.dplyr.filter() now achieves similar performance as DataFrame.loc[].

from datar.

pwwang avatar pwwang commented on August 11, 2024

There could be cython functions called inside DataFrame.query(), but I need to confirm.
However, before that, we can confirm whether it is because of the optimization inside DataFrame.query() or somewhere else. Could you try this:

conditions = (df_test.Description =="WHITE HANGING HEART T-LIGHT HOLDER" ) | (df_test.Description =="REGENCY CAKESTAN
D 3 TIER")

%%time
filter(df_test, conditions)

%%time
df_test[conditions]

from datar.

rleyvasal avatar rleyvasal commented on August 11, 2024

Here is the output
output1
output2

from datar.

pwwang avatar pwwang commented on August 11, 2024

Looks like that 20x time was optimized inside .query(). One of the reasons might be that the data in the conditions are from inside the data frame itself.

What if you do:

descr = df_test.Description.copy()
df_test.query('(@descr == "WHITE HANGING HEART T-LIGHT HOLDER") | (@descr == "REGENCY CAKESTAND 3 TIER")')

from datar.

pwwang avatar pwwang commented on August 11, 2024

The condition aggregation is also eating the time up. There is an extra calculation:

# check condition, conditions
    condition = Array([True] * _data.shape[0])
    for cond in conditions:
        if is_scalar(cond):
            cond = Array([cond] * _data.shape[0])
        condition = condition & cond

    condition[is_null(condition)] = False
    try:
        condition = condition.values.flatten()
    except AttributeError:
        ...

    out = _data[condition]

that I used an initial array with all Trues. Let's try to use the first condition passed in as the initial condition and see if it helps.

Might need a prun to profile which steps are eating up the time.

from datar.

pwwang avatar pwwang commented on August 11, 2024

See: https://pwwang.github.io/datar/performance/#datar.dplyr.filter()-vs-DataFrame.loc%5B%5D-vs-DataFrame.query()

from datar.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.