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

feat: SparkLikeNamespace methods #1779

Merged
merged 7 commits into from
Jan 10, 2025
Merged

feat: SparkLikeNamespace methods #1779

merged 7 commits into from
Jan 10, 2025

Conversation

FBruzzesi
Copy link
Member

What type of PR is this? (check all applicable)

  • πŸ’Ύ Refactor
  • ✨ Feature
  • πŸ› Bug Fix
  • πŸ”§ Optimization
  • πŸ“ Documentation
  • βœ… Test
  • 🐳 Other

Related issues

Checklist

  • Code follows style guide (ruff)
  • Tests added
  • Documented the changes

If you have comments or can explain your changes, please do so below

Introduces:

  • Expr.is_null
  • Expr.n_unique
  • Namespace.len
  • Namespace.any_horizontal
  • Namespace.mean_horizontal
  • Namespace.min_horizontal
  • Namespace.max_horizontal
  • Namespace.concat
  • Namespace.concat_str

tests/utils.py Outdated
Comment on lines 68 to 70
sorted_indices = sorted(
range(len(sort_list)), key=lambda i: (sort_list[i] is None, sort_list[i])
)
Copy link
Member Author

Choose a reason for hiding this comment

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

Otherwise list with Nones would just fail to sort

from pyspark.sql.types import IntegerType

def _n_unique(_input: Column) -> Column:
return F.count_distinct(_input) + F.max(F.isnull(_input).cast(IntegerType()))
Copy link
Member Author

Choose a reason for hiding this comment

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

Highly inspired by duckdb implementation πŸ˜‚πŸ˜‰

expr._function_name, expr._function_name
)
agg_func = get_spark_function(function_name, **expr._kwargs)
agg_func = get_spark_function(expr._function_name, **expr._kwargs)
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 could not manage to make nw.len() work in the group_by context

@FBruzzesi
Copy link
Member Author

@MarcoGorelli scikit-lego issue is definitly unrelated

@FBruzzesi FBruzzesi added the enhancement New feature or request label Jan 10, 2025
Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

awesome, glad that you're thinking about the mean_horizontal tricky implementation πŸ˜„ πŸ™Œ

@MarcoGorelli MarcoGorelli merged commit 8229282 into main Jan 10, 2025
21 of 23 checks passed
@MarcoGorelli MarcoGorelli deleted the feat/pyspark-namespace branch January 10, 2025 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants