Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 13 additions & 0 deletions python/pyspark/pandas/tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -6044,6 +6044,19 @@ def test_mode(self):
with self.assertRaises(ValueError):
psdf.mode(axis=2)

def f(index, iterator):
return ["3", "3", "3", "3", "4"] if index == 3 else ["0", "1", "2", "3", "4"]

rdd = self.spark.sparkContext.parallelize(
[
1,
],
4,
Comment on lines +6050 to +6054
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can we just is one or two line some thing like:

rdd = self.spark.sparkContext.parallelize([1], 4)
    .mapPartitionsWithIndex(f)

?? I suspect it's maybe adjusted by black script tho, 😂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it was just reformated by the script😅

).mapPartitionsWithIndex(f)
df = self.spark.createDataFrame(rdd, schema="string")
psdf = df.pandas_api()
self.assert_eq(psdf.mode(), psdf._to_pandas().mode())

def test_abs(self):
pdf = pd.DataFrame({"a": [-2, -1, 0, 1]})
psdf = ps.from_pandas(pdf)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,12 @@ case class PandasMode(
override def update(
buffer: OpenHashMap[AnyRef, Long],
input: InternalRow): OpenHashMap[AnyRef, Long] = {
val key = child.eval(input).asInstanceOf[AnyRef]
val key = child.eval(input)

if (key != null || !ignoreNA) {
buffer.changeValue(key, 1L, _ + 1L)
if (key != null) {
buffer.changeValue(InternalRow.copyValue(key).asInstanceOf[AnyRef], 1L, _ + 1L)
} else if (!ignoreNA) {
buffer.changeValue(null, 1L, _ + 1L)
}
buffer
}
Expand Down