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

Cannot filter for strings #19

Closed
1 of 2 tasks
forgetso opened this issue Nov 16, 2022 · 3 comments
Closed
1 of 2 tasks

Cannot filter for strings #19

forgetso opened this issue Nov 16, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@forgetso
Copy link

forgetso commented Nov 16, 2022

Have you tried latest version of polars?

  • yes
  • no

What version of polars are you using?

nodejs-polars@0.6.0

What operating system are you using polars on?

Linux 5.4.0-132-generic #148-Ubuntu

What node version are you using

node --version
v16.13.2

Describe your bug.

Cannot filter for string values

What are the steps to reproduce the behavior?

> df = pl.DataFrame({"foo": ["a", "b", "c"]})
Proxy [
  shape: (3, 1)
  ┌─────┐
   foo 
   --- 
   str 
  ╞═════╡
   a   
  ├╌╌╌╌╌┤
   b   
  ├╌╌╌╌╌┤
   c   
  └─────┘,
  {
    get: [Function: get],
    set: [Function: set],
    has: [Function: has],
    ownKeys: [Function: ownKeys],
    getOwnPropertyDescriptor: [Function: getOwnPropertyDescriptor]
  }
]
> df.filter(pl.col("foo").eq("b"))
Uncaught Error: Not found: b
    at Object.collectSync (/home/user/dev/workspaces/node_modules/nodejs-polars/bin/lazy/dataframe.js:62:53)
    at Proxy.filter (/home/user/dev/workspaces/node_modules/nodejs-polars/bin/dataframe.js:155:18) {
  code: 'GenericFailure'
}

What is the actual behavior?

The filter fails

What is the expected behavior?

The filter should succeed

Additional Info

You can get around this error by placing the string value in a series

> df = pl.DataFrame({"foo": ["a", "b", "c"]})
Proxy [
  shape: (3, 1)
  ┌─────┐
  │ foo │
  │ --- │
  │ str │
  ╞═════╡
  │ a   │
  ├╌╌╌╌╌┤
  │ b   │
  ├╌╌╌╌╌┤
  │ c   │
  └─────┘,
  {
    get: [Function: get],
    set: [Function: set],
    has: [Function: has],
    ownKeys: [Function: ownKeys],
    getOwnPropertyDescriptor: [Function: getOwnPropertyDescriptor]
  }
]
> df.filter(pl.col("foo").eq(pl.Series(["b"])))
Proxy [
  shape: (1, 1)
  ┌─────┐
  │ foo │
  │ --- │
  │ str │
  ╞═════╡
  │ b   │
  └─────┘,
  {
    get: [Function: get],
    set: [Function: set],
    has: [Function: has],
    ownKeys: [Function: ownKeys],
    getOwnPropertyDescriptor: [Function: getOwnPropertyDescriptor]
  }
]

@forgetso forgetso added the bug Something isn't working label Nov 16, 2022
@universalmind303
Copy link
Collaborator

when using strings, you need to use lit

df.filter(pl.col("foo").eq(pl.lit("b"))

@daolanfler
Copy link

I think the filter api's doc needs an update. it's not using pl.lit when comparing strings ....
image

@badele
Copy link

badele commented Jan 4, 2024

I'm using Polars with JavaScript (Deno). I spent a considerable amount of time searching through the documentation before stumbling upon this issue (it was the last test I performed before deciding to stop using Polars).

It seems necessary to either create an alias like compareString or clearly state in the documentation that, since the Polar version for Node.js, it is now required to use the following code:

const scan = await pl.scanCSV("database/.export/symbols_history.csv", {
  sep: ";",
  quoteChar: '"',
  parseDates: true,
}).select(["SYMBOL", "DATE", "Industry", "price"])
  .filter(
    pl.col("SYMBOL").eq(pl.lit("AI")),
  )
  .collect();

This could prevent any confusion and facilitate the transition to the new Polar practices."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants