Giter Site home page Giter Site logo

Panic on SchemaMismatch about polars HOT 5 CLOSED

tkellogg avatar tkellogg commented on July 20, 2024
Panic on SchemaMismatch

from polars.

Comments (5)

deanm0000 avatar deanm0000 commented on July 20, 2024

As an alternative

pl.concat([a, a.select(pl.lit(0).alias("a"))], how='vertical_relaxed')

does what you expect.

It makes sense to me that a python int would be treated the same between the different constructors. I'm not sure if there's a reason for the difference or it is just chance. @stinodego what do you think?

from polars.

tkellogg avatar tkellogg commented on July 20, 2024

In addition, I wouldn't mind sending a patch for this. I would have, but I wanted to check first that it wasn't more complicated than it appeared. LMK

from polars.

stinodego avatar stinodego commented on July 20, 2024

A patch to turn the panic into a proper error is welcome!

It makes sense to me that a python int would be treated the same between the different constructors. I'm not sure if there's a reason for the difference or it is just chance. @stinodego what do you think?

There is a reason for the existing behavior, though off the top of my head I don't know why. Something to do with the difference between eager and lazy.

from polars.

tkellogg avatar tkellogg commented on July 20, 2024

PR is ready to be reviewed. Pretty simple, I didn't try to address the inconsistent int handling.

@stinodego, if I were to guess, I bet the problem is that lazy Series can't infer a int32 without scanning it first, so it assumes int64. Whereas lit can trivially assume int64, and does. I'm not sure there's an easy way to fix this without breaking backward compatibility.

from polars.

ritchie46 avatar ritchie46 commented on July 20, 2024

I didn't try to address the inconsistent int handling.

The lit int handling isn't something trivial. Literals should behave different from the constructor. They are dynamic and often need to depend on the operation to define their required type. E.g. multiply a int8 column with lit(1) should not upcast the int8 column.

If the lit is used in isolation, we try to fit a reasonably small dtype that fits. Currently that is int32. Smaller often leads to unexpected overflows. If the literal given doesn't fit int32 it is upcast to int64 or even uint64 if needed.

For the constructor we need to be more conservative as we don't want to inspect the whole array up front, whereas with a literal this is cheap, so we go with int64. If you need other behavior, you need to specify your dtype.

In a future version it might be possible that we recognize the dynamic literal usage across contexts and recognized that you were concatting to a i64, but this isn't trivial and I think also not worth the compute cost.

from polars.

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.