Skip to content

Commit

Permalink
Merge branch 'narwhals-dev:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ugohuche authored Jul 5, 2024
2 parents 05e01e5 + cc2c1f1 commit 58db355
Show file tree
Hide file tree
Showing 13 changed files with 200 additions and 95 deletions.
1 change: 1 addition & 0 deletions docs/api-reference/expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
handler: python
options:
members:
- abs
- alias
- all
- any
Expand Down
1 change: 1 addition & 0 deletions docs/api-reference/series.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
handler: python
options:
members:
- abs
- alias
- all
- any
Expand Down
2 changes: 1 addition & 1 deletion docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ Then, if you start the Python REPL and see the following:
```python
>>> import narwhals
>>> narwhals.__version__
'0.9.27'
'0.9.28'
```
then installation worked correctly!
2 changes: 1 addition & 1 deletion narwhals/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
from narwhals.utils import maybe_convert_dtypes
from narwhals.utils import maybe_set_index

__version__ = "0.9.27"
__version__ = "0.9.28"

__all__ = [
"selectors",
Expand Down
3 changes: 3 additions & 0 deletions narwhals/_arrow/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ def __narwhals_namespace__(self) -> ArrowNamespace:
def cast(self, dtype: DType) -> Self:
return reuse_series_implementation(self, "cast", dtype) # type: ignore[type-var]

def abs(self) -> Self:
return reuse_series_implementation(self, "abs") # type: ignore[type-var]

def cum_sum(self) -> Self:
return reuse_series_implementation(self, "cum_sum") # type: ignore[type-var]

Expand Down
4 changes: 4 additions & 0 deletions narwhals/_arrow/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ def alias(self, name: str) -> Self:
def dtype(self) -> DType:
return translate_dtype(self._series.type)

def abs(self) -> Self:
pc = get_pyarrow_compute()
return self._from_series(pc.abs(self._series))

def cum_sum(self) -> Self:
pc = get_pyarrow_compute()
return self._from_series(pc.cumulative_sum(self._series))
Expand Down
3 changes: 3 additions & 0 deletions narwhals/_pandas_like/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ def drop_nulls(self) -> Self:
def sort(self, *, descending: bool = False) -> Self:
return reuse_series_implementation(self, "sort", descending=descending)

def abs(self) -> Self:
return reuse_series_implementation(self, "abs")

def cum_sum(self) -> Self:
return reuse_series_implementation(self, "cum_sum")

Expand Down
3 changes: 3 additions & 0 deletions narwhals/_pandas_like/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,9 @@ def sample(
ser = self._series
return self._from_series(ser.sample(n=n, frac=fraction, replace=with_replacement))

def abs(self) -> PandasSeries:
return self._from_series(self._series.abs())

def cum_sum(self) -> PandasSeries:
return self._from_series(self._series.cumsum())

Expand Down
8 changes: 4 additions & 4 deletions narwhals/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,9 @@ def __getitem__(self, item: Sequence[int]) -> Series: ...
def __getitem__(self, item: str) -> Series: ...

@overload
def __getitem__(self, item: slice) -> DataFrame: ...
def __getitem__(self, item: slice) -> Self: ...

def __getitem__(self, item: str | slice | Sequence[int]) -> Series | DataFrame:
def __getitem__(self, item: str | slice | Sequence[int]) -> Series | Self:
if isinstance(item, str):
from narwhals.series import Series

Expand Down Expand Up @@ -1649,7 +1649,7 @@ def is_unique(self: Self) -> Series:

return Series(self._dataframe.is_unique())

def null_count(self: Self) -> DataFrame:
def null_count(self: Self) -> Self:
r"""
Create a new DataFrame that shows the null counts per column.
Expand Down Expand Up @@ -1814,7 +1814,7 @@ def __repr__(self) -> str: # pragma: no cover
+ "┘"
)

def __getitem__(self, item: str | slice) -> Series | DataFrame:
def __getitem__(self, item: str | slice) -> Series | Self:
raise TypeError("Slicing is not supported on LazyFrame")

def collect(self) -> DataFrame:
Expand Down
Loading

0 comments on commit 58db355

Please sign in to comment.