Skip to content

Commit

Permalink
fix(python): fix and test df.corr (#7463)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 authored Mar 10, 2023
1 parent 59e7349 commit 4ad4930
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/deploy_manylinux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ls -la
rm py-polars/README.md
cp README.md py-polars/README.md
cd py-polars
rustup override set nightly-2023-03-09
rustup override set nightly-2023-03-10
export RUSTFLAGS='-C target-feature=+fxsr,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt,+avx,+fma'

# first the default release
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
- name: Set up Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly-2023-03-09
toolchain: nightly-2023-03-10

- name: Cache Rust
uses: Swatinem/rust-cache@v2
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/build-test-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: Set up Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly-2023-03-09
toolchain: nightly-2023-03-10

- name: Cache Rust
uses: Swatinem/rust-cache@v2
Expand All @@ -58,7 +58,7 @@ jobs:
- name: Set up Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly-2023-03-09
toolchain: nightly-2023-03-10
components: rustfmt, clippy, miri

- name: Cache Rust
Expand Down Expand Up @@ -102,7 +102,7 @@ jobs:
- name: Set up Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly-2023-03-09
toolchain: nightly-2023-03-10

- name: Cache Rust
uses: Swatinem/rust-cache@v2
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/create-python-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
MATURIN_PASSWORD: ${{ secrets.PYPI_PASS }}
RUSTFLAGS: -C target-feature=+fxsr,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt,+avx,+fma
with:
rust-toolchain: nightly-2023-03-09
rust-toolchain: nightly-2023-03-10
maturin-version: '0.14.10'
command: publish
args: -m py-polars/Cargo.toml --skip-existing -o wheels -u ritchie46
Expand All @@ -54,7 +54,7 @@ jobs:
MATURIN_PASSWORD: ${{ secrets.PYPI_PASS }}
JEMALLOC_SYS_WITH_LG_PAGE: 16
with:
rust-toolchain: nightly-2023-03-09
rust-toolchain: nightly-2023-03-10
target: aarch64-unknown-linux-gnu
maturin-version: '0.14.10'
command: publish
Expand Down Expand Up @@ -85,7 +85,7 @@ jobs:
MATURIN_PASSWORD: ${{ secrets.PYPI_PASS }}
RUSTFLAGS: -C target-feature=+fxsr,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt,+avx,+fma
with:
rust-toolchain: nightly-2023-03-09
rust-toolchain: nightly-2023-03-10
maturin-version: '0.14.10'
command: publish
args: -m py-polars/Cargo.toml --skip-existing -o wheels -u ritchie46
Expand All @@ -112,7 +112,7 @@ jobs:
MATURIN_PASSWORD: ${{ secrets.PYPI_PASS }}
RUSTFLAGS: -C target-feature=+fxsr,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt --cfg use_mimalloc
with:
rust-toolchain: nightly-2023-03-09
rust-toolchain: nightly-2023-03-10
maturin-version: '0.14.10'
command: publish
args: -m py-polars/Cargo.toml --skip-existing -o wheels -u ritchie46
Expand Down Expand Up @@ -141,7 +141,7 @@ jobs:
MATURIN_PASSWORD: ${{ secrets.PYPI_PASS }}
RUSTFLAGS: -C target-feature=+fxsr,+sse,+sse2,+sse3,+sse4.1,+sse4.2
with:
rust-toolchain: nightly-2023-03-09
rust-toolchain: nightly-2023-03-10
maturin-version: '0.14.10'
command: publish
args: -m py-polars/Cargo.toml --no-sdist --skip-existing -o wheels -i python -u ritchie46
Expand All @@ -162,7 +162,7 @@ jobs:
- name: Set up Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly-2023-03-09
toolchain: nightly-2023-03-10

- name: Set up Rust targets
run: rustup target add aarch64-apple-darwin
Expand Down Expand Up @@ -194,7 +194,7 @@ jobs:
# - name: Set up Rust
# uses: dtolnay/rust-toolchain@master
# with:
# toolchain: nightly-2023-03-09
# toolchain: nightly-2023-03-10

# - name: Set up Rust targets
# run: rustup target add aarch64-apple-darwin
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs-deploy-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Set up Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly-2023-03-09
toolchain: nightly-2023-03-10
components: rust-docs

- name: Cache Rust
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
- name: Set up Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly-2023-03-09
toolchain: nightly-2023-03-10
components: rustfmt, clippy

- name: Cache Rust
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
- name: Set up Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly-2023-03-09
toolchain: nightly-2023-03-10

- name: Cache Rust
uses: Swatinem/rust-cache@v2
Expand Down Expand Up @@ -109,7 +109,7 @@ jobs:
- name: Set up Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly-2023-03-09
toolchain: nightly-2023-03-10

- name: Cache Rust
uses: Swatinem/rust-cache@v2
Expand Down
7 changes: 3 additions & 4 deletions py-polars/polars/internals/dataframe/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -8030,11 +8030,10 @@ def corr(self, **kwargs: Any) -> Self:
└──────┴──────┴──────┘
"""
corr = np.corrcoef(self, **kwargs)
names = self.columns
return self._from_pydf(
DataFrame(
np.corrcoef(self, **kwargs),
schema=self.columns,
)._df
DataFrame([pli.Series(names[i], corr[i, :]) for i in range(len(names))])._df
)

def merge_sorted(self, other: DataFrame, key: str) -> Self:
Expand Down
14 changes: 14 additions & 0 deletions py-polars/tests/unit/operations/test_statistics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import polars as pl


def test_corr() -> None:
df = pl.DataFrame(
{
"a": [1, 2, 4],
"b": [-1, 23, 8],
}
)
assert df.corr().to_dict(False) == {
"a": [1.0, 0.18898223650461357],
"b": [0.1889822365046136, 1.0],
}
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[toolchain]
channel = "nightly-2023-03-09"
channel = "nightly-2023-03-10"

0 comments on commit 4ad4930

Please sign in to comment.