Coder Social home page Coder Social logo

Comments (4)

harpaj avatar harpaj commented on June 1, 2024

@zero323,
The following valid snippet currently results in an error:

df = df.withColumn("score", sum((F.col("sim"), F.col("weight"))))
(note that sum is the stdlib sum, not the one from pyspark functions)

The error is Argument 2 to "withColumn" of "DataFrame" has incompatible type "Union[Column, int]"; expected "Column"

We actually do have a proper annotation for radd on Column, but it has a type: ignore. It sounds like this is connected to the python/mypy#2129 you mention above, but that one has been fixed. Do you think the type: ignore can be safely removed now?

from pyspark-stubs.

zero323 avatar zero323 commented on June 1, 2024

@harpaj Indeed, it looks like it should be safe to remove type: ignore now.

However I don't think that's really the source of the problem here. With ingore this for example is valid:

expr: Column = 1 + col("b")

It looks like the problem is more that we don't have dependent types here, and mypy cannot infer that sum(NonEmptyIterable[Column]) is Column. Instead in consider both cases:

  • iterable is empty and we default to int,
  • iterable is non empty and we get Column

If you want sum to type check you should rather start with literal

sum([F.col("sim"), F.col("weight")], lit(0))

from pyspark-stubs.

zero323 avatar zero323 commented on June 1, 2024

Partially addressed by #194

from pyspark-stubs.

github-actions avatar github-actions commented on June 1, 2024

This issue haven't seen any activity in a while.

from pyspark-stubs.

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.