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

Use pandas' transpose when the data is expected to be small. #1932

Merged
merged 2 commits into from
Nov 26, 2020
Merged
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
9 changes: 4 additions & 5 deletions databricks/koalas/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ def _reduce_for_stat_function(self, sfun, name, axis=None, numeric_only=True):
sdf = self._internal.spark_frame.select(*exprs)

# The data is expected to be small so it's fine to transpose/use default index.
with ks.option_context("compute.max_rows", None):
with ks.option_context("compute.max_rows", 1):
internal = InternalFrame(
spark_frame=sdf,
index_spark_column_names=[SPARK_DEFAULT_INDEX_NAME],
Expand Down Expand Up @@ -3806,7 +3806,7 @@ def nunique(
)

# The data is expected to be small so it's fine to transpose/use default index.
with ks.option_context("compute.max_rows", None):
with ks.option_context("compute.max_rows", 1):
internal = self._internal.copy(
spark_frame=sdf,
index_spark_column_names=[SPARK_DEFAULT_INDEX_NAME],
Expand All @@ -3815,7 +3815,6 @@ def nunique(
scol_for(sdf, col) for col in self._internal.data_spark_column_names
],
)

return first_series(DataFrame(internal).transpose())

def round(self, decimals=0) -> "DataFrame":
Expand Down Expand Up @@ -10495,14 +10494,14 @@ def get_spark_column(kdf, label):
[F.lit(None).cast(StringType()).alias(SPARK_DEFAULT_INDEX_NAME)] + new_columns
)

with ks.option_context("compute.max_rows", None):
# The data is expected to be small so it's fine to transpose/use default index.
with ks.option_context("compute.max_rows", 1):
internal = InternalFrame(
spark_frame=sdf,
index_spark_column_names=[SPARK_DEFAULT_INDEX_NAME],
column_labels=new_column_labels,
column_label_names=self._internal.column_label_names,
)

return first_series(DataFrame(internal).transpose())

else:
Expand Down
4 changes: 1 addition & 3 deletions databricks/koalas/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -4955,9 +4955,7 @@ def asof(self, where) -> Union[Scalar, "Series"]:
return result if result is not None else np.nan

# The data is expected to be small so it's fine to transpose/use default index.
with ks.option_context(
"compute.default_index_type", "distributed", "compute.max_rows", None
):
with ks.option_context("compute.default_index_type", "distributed", "compute.max_rows", 1):
kdf = ks.DataFrame(sdf) # type: DataFrame
kdf.columns = pd.Index(where)
return first_series(kdf.transpose()).rename(self.name)
Expand Down