Skip to content

Conversation

@liamholmes31
Copy link
Contributor

@liamholmes31 liamholmes31 commented Dec 22, 2025

Description

Added sin expr/series methods.

Have tried to follow existing PRs adding e.g. log methods - was a bit hazy on which classes in _compliant I needed to add these to, so apologies if anything is missing!

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

@liamholmes31 liamholmes31 marked this pull request as draft December 22, 2025 11:51
def last(self) -> Self: ...
def skew(self) -> Self: ...
def kurtosis(self) -> Self: ...
def sin(self) -> Self: ...
Copy link
Member

Choose a reason for hiding this comment

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

@liamholmes31 I see that you removed this, but it was on the right track!

Do you mind if I add a commit with where this should be defined?
The file isn't in the changes so I couldn't use a suggestion

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, thanks @dangotbanned !

Copy link
Member

@dangotbanned dangotbanned Dec 22, 2025

Choose a reason for hiding this comment

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

Please excuse the typo 🤦‍♂️
fix: Add ComplianColumn.sin

We should probably document this better!

All the methods that Expr and Series share and use Self can be added to CompliantColumn

class CompliantColumn(Protocol):
"""Common parts of `Expr`, `Series`."""

So for example, CompliantColumn.log is here, since it works elementwise:

def log(self, base: float) -> Self: ...

But for something like first, we need two separate definitions:

Here we aggregate to a literal value

def first(self) -> PythonLiteral: ...

But here the aggregation is a literal expression

def first(self) -> Self: ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ahh OK this makes sense, thanks!! I was thrown by not spotting where log was defined in compliant, should have looked a bit harder!

@dangotbanned dangotbanned linked an issue Dec 22, 2025 that may be closed by this pull request
@dangotbanned dangotbanned changed the title Feat/sin methods feat: Add {Expr,Series}.sin Dec 22, 2025
@dangotbanned dangotbanned added the enhancement New feature or request label Dec 22, 2025
@liamholmes31
Copy link
Contributor Author

might need some advice on the failing type check CI stage (see below), looks like the type hint for 'pc_func' may need to be relaxed?

  /home/runner/work/narwhals/narwhals/narwhals/_pandas_like/series.py:1098:70 - error: Argument of type "Overload[(x: pyarrow.compute.FloatScalar, /, *, memory_pool: MemoryPool | None = None) -> (pyarrow.__lib_pxi.scalar.FloatScalar | DoubleScalar), (x: FloatArray, /, *, memory_pool: MemoryPool | None = None) -> (NumericArray[pyarrow.__lib_pxi.scalar.FloatScalar] | NumericArray[DoubleScalar]), (x: Expression, /, *, memory_pool: MemoryPool | None = None) -> Expression]" cannot be assigned to parameter "pc_func" of type "(ChunkedArrayAny) -> ChunkedArrayAny" in function "_apply_pyarrow_compute_func"
    No overloaded function matches type "(ChunkedArrayAny) -> ChunkedArrayAny" (reportArgumentType)

@liamholmes31
Copy link
Contributor Author

some of the failing downstream stages don't look obviously related to my changes here, are these known failing steps?

@FBruzzesi
Copy link
Member

Hey @liamholmes31 thanks for you PR 🚀 Looking forward to finalize it

some of the failing downstream stages don't look obviously related to my changes here, are these known failing steps?

They surely aren't related with the changes, we will address them separately or report the issues downstream 😉

@MarcoGorelli
Copy link
Member

might need some advice on the failing type check CI stage (see below), looks like the type hint for 'pc_func' may need to be relaxed?

  /home/runner/work/narwhals/narwhals/narwhals/_pandas_like/series.py:1098:70 - error: Argument of type "Overload[(x: pyarrow.compute.FloatScalar, /, *, memory_pool: MemoryPool | None = None) -> (pyarrow.__lib_pxi.scalar.FloatScalar | DoubleScalar), (x: FloatArray, /, *, memory_pool: MemoryPool | None = None) -> (NumericArray[pyarrow.__lib_pxi.scalar.FloatScalar] | NumericArray[DoubleScalar]), (x: Expression, /, *, memory_pool: MemoryPool | None = None) -> Expression]" cannot be assigned to parameter "pc_func" of type "(ChunkedArrayAny) -> ChunkedArrayAny" in function "_apply_pyarrow_compute_func"
    No overloaded function matches type "(ChunkedArrayAny) -> ChunkedArrayAny" (reportArgumentType)

looks like an issue with pyarrow-stubs, i'd suggest just type-ignoring (and ideally reporting upstream)

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.

[Enh]: add Expr.sin and Series.sin

4 participants