Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions python/pyspark/sql/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4680,6 +4680,26 @@ def test_supported_types(self):
self.assertPandasEqual(expected2, result2)
self.assertPandasEqual(expected3, result3)

def test_array_type_correct(self):
from pyspark.sql.functions import pandas_udf, PandasUDFType, array, col

df = self.data.withColumn("arr", array(col("id"))).repartition(1, "id")

output_schema = StructType(
[StructField('id', LongType()),
StructField('v', IntegerType()),
StructField('arr', ArrayType(LongType()))])

udf = pandas_udf(
lambda pdf: pdf,
output_schema,
PandasUDFType.GROUPED_MAP
)

result = df.groupby('id').apply(udf).sort('id').toPandas()
expected = df.toPandas().groupby('id').apply(udf.func).reset_index(drop=True)
self.assertPandasEqual(expected, result)

def test_register_grouped_map_udf(self):
from pyspark.sql.functions import pandas_udf, PandasUDFType

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ private[arrow] class ArrayWriter(
override def reset(): Unit = {
super.reset()
elementWriter.reset()
valueVector.clear()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks @BryanCutler added reset() interface in 0.9.0 mentioned in:

// TODO: reset() should be in a common interface

at apache/arrow@4dbce60 and https://issues.apache.org/jira/browse/ARROW-1962

but if we think about backporting, probably I guess we can go this way as a bug fix as is? Roughly looks making sense.

Would it be also safe to do:

    valueVector match {
      case fixedWidthVector: BaseFixedWidthVector => fixedWidthVector.reset()
      case variableWidthVector: BaseVariableWidthVector => variableWidthVector.reset()
      case repeatedValueVector: BaseRepeatedValueVector => repeatedValueVector.clear()
      case _ =>
    }

? @icexelloss, @BryanCutler and @viirya?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think so.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've also noticed that @BryanCutler added reset to ListVector. But we can only use clear for now.

}
}

Expand Down