Skip to content

Commit

Permalink
Fix dtypes for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
stinodego committed Jan 30, 2023
1 parent a6b37e6 commit 6632e40
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
19 changes: 13 additions & 6 deletions py-polars/tests/unit/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def test_init_ndarray(monkeypatch: Any) -> None:
assert_frame_equal(df, pl.DataFrame())

# 1D array
df = pl.DataFrame(np.array([1, 2, 3]), schema=["a"])
df = pl.DataFrame(np.array([1, 2, 3], dtype=np.int64), schema=["a"])
expected = pl.DataFrame({"a": [1, 2, 3]})
assert_frame_equal(df, expected)

Expand All @@ -180,7 +180,10 @@ def test_init_ndarray(monkeypatch: Any) -> None:
assert_frame_equal(df, expected)

# 2D array (or 2x 1D array) - should default to column orientation
for data in (np.array([[1, 2], [3, 4]]), [np.array([1, 2]), np.array([3, 4])]):
for data in (
np.array([[1, 2], [3, 4]], dtype=np.int64),
[np.array([1, 2], dtype=np.int64), np.array([3, 4], dtype=np.int64)],
):
df = pl.DataFrame(data, orient="col")
expected = pl.DataFrame({"column_0": [1, 2], "column_1": [3, 4]})
assert_frame_equal(df, expected)
Expand All @@ -200,21 +203,25 @@ def test_init_ndarray(monkeypatch: Any) -> None:
assert df.schema == {"x": pl.Boolean, "y": pl.Int32, "z": pl.Utf8}

# 2D array - default to column orientation
df = pl.DataFrame(np.array([[1, 2], [3, 4]]))
df = pl.DataFrame(np.array([[1, 2], [3, 4]], dtype=np.int64))
expected = pl.DataFrame({"column_0": [1, 3], "column_1": [2, 4]})
assert_frame_equal(df, expected)

# no orientation is numpy convention
df = pl.DataFrame(np.ones((3, 1)))
df = pl.DataFrame(np.ones((3, 1), dtype=np.int64))
assert df.shape == (3, 1)

# 2D array - row orientation inferred
df = pl.DataFrame(np.array([[1, 2, 3], [4, 5, 6]]), schema=["a", "b", "c"])
df = pl.DataFrame(
np.array([[1, 2, 3], [4, 5, 6]], dtype=np.int64), schema=["a", "b", "c"]
)
expected = pl.DataFrame({"a": [1, 4], "b": [2, 5], "c": [3, 6]})
assert_frame_equal(df, expected)

# 2D array - column orientation inferred
df = pl.DataFrame(np.array([[1, 2, 3], [4, 5, 6]]), schema=["a", "b"])
df = pl.DataFrame(
np.array([[1, 2, 3], [4, 5, 6]], dtype=np.int64), schema=["a", "b"]
)
expected = pl.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
assert_frame_equal(df, expected)

Expand Down
3 changes: 2 additions & 1 deletion py-polars/tests/unit/test_df.py
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,8 @@ def test_multiple_column_sort() -> None:
assert list(out["c"]) == [2.0, 1.0, 3.0]
assert list(out["b"]) == [2, 2, 3]

df = pl.DataFrame({"a": np.arange(1, 4), "b": ["a", "a", "b"]})
# Explicitly specify numpy dtype because of different defaults on Windows
df = pl.DataFrame({"a": np.arange(1, 4, dtype=np.int64), "b": ["a", "a", "b"]})

assert_frame_equal(
df.sort("a", reverse=True), pl.DataFrame({"a": [3, 2, 1], "b": ["b", "a", "a"]})
Expand Down
9 changes: 5 additions & 4 deletions py-polars/tests/unit/test_joins.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,18 +539,19 @@ def test_with_pd(
@typing.no_type_check
def test_jit_sort_joins() -> None:
n = 200
# Explicitly specify numpy dtype because of different defaults on Windows
dfa = pd.DataFrame(
{
"a": np.random.randint(0, 100, n),
"b": np.arange(0, n),
"a": np.random.randint(0, 100, n, dtype=np.int64),
"b": np.arange(0, n, dtype=np.int64),
}
)

n = 40
dfb = pd.DataFrame(
{
"a": np.random.randint(0, 100, n),
"b": np.arange(0, n),
"a": np.random.randint(0, 100, n, dtype=np.int64),
"b": np.arange(0, n, dtype=np.int64),
}
)
dfa_pl = pl.from_pandas(dfa).sort("a")
Expand Down

0 comments on commit 6632e40

Please sign in to comment.