Skip to content

Commit

Permalink
add api reference index
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli committed Apr 3, 2024
1 parent 191ca49 commit 34dfe88
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ nav:
- Roadmap: roadmap.md
- Related projects: related.md
- API Reference:
- api-reference/index.md
- api-reference/narwhals.md
- api-reference/dataframe.md
- api-reference/lazyframe.md
Expand All @@ -25,6 +26,7 @@ theme:
- content.code.copy
- content.code.annotate
- navigation.footer
- navigation.indexes
plugins:
- search
- mkdocstrings:
Expand Down
8 changes: 8 additions & 0 deletions narwhals/_pandas_like/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,14 @@ def mean(self) -> Any:
ser = self._series
return ser.mean()

def std(
self,
*,
correction: float = 1.0,
) -> Any:
ser = self._series
return ser.std(ddof=correction)

def len(self) -> Any:
return len(self._series)

Expand Down
6 changes: 6 additions & 0 deletions narwhals/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ def cast(
self._series.cast(translate_dtype(self.__narwhals_namespace__(), dtype))
)

def mean(self) -> Any:
return self._series.mean()

def std(self) -> Any:
return self._series.std()

def is_in(self, other: Any) -> Self:
return self._from_series(self._series.is_in(self._extract_native(other)))

Expand Down
6 changes: 6 additions & 0 deletions tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ def test_dtype(df_raw: Any) -> None:
assert result.is_numeric()


@pytest.mark.parametrize("df_raw", [df_pandas, df_lazy])
def test_reductions(df_raw: Any) -> None:
assert nw.LazyFrame(df_raw).collect()["a"].mean() == 2.0
assert nw.LazyFrame(df_raw).collect()["a"].std() == 1.0


@pytest.mark.parametrize("df_raw", [df_pandas, df_lazy])
def test_convert(df_raw: Any) -> None:
result = nw.LazyFrame(df_raw).collect()["a"].to_numpy()
Expand Down

0 comments on commit 34dfe88

Please sign in to comment.