Skip to content

Commit

Permalink
fix to_pandas|numpy
Browse files Browse the repository at this point in the history
  • Loading branch information
FBruzzesi committed Jul 10, 2024
1 parent b29d583 commit 46e374b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def pandas_constructor(obj: Any) -> IntoDataFrame:


def pandas_nullable_constructor(obj: Any) -> IntoDataFrame:
return pd.DataFrame(obj).convert_dtypes() # type: ignore[no-any-return]
return pd.DataFrame(obj).convert_dtypes(dtype_backend="numpy_nullable") # type: ignore[no-any-return]


def pandas_pyarrow_constructor(obj: Any) -> IntoDataFrame:
Expand Down
4 changes: 2 additions & 2 deletions tests/frame/to_numpy_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@


def test_convert_numpy(constructor: Any) -> None:
data = {"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]}
data = {"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.1, 8, 9]}
df_raw = constructor(data)
result = nw.from_native(df_raw, eager_only=True).to_numpy()

expected = np.array([[1, 3, 2], [4, 4, 6], [7.0, 8, 9]]).T
expected = np.array([[1, 3, 2], [4, 4, 6], [7.1, 8, 9]]).T
np.testing.assert_array_equal(result, expected)
assert result.dtype == "float64"

Expand Down
7 changes: 6 additions & 1 deletion tests/frame/to_pandas_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,10 @@ def test_convert_pandas(constructor_with_pyarrow: Any) -> None:
data = {"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]}
df_raw = constructor_with_pyarrow(data)
result = nw.from_native(df_raw).to_pandas() # type: ignore[union-attr]
expected = pd.DataFrame(data)

if constructor_with_pyarrow.__name__.startswith("pandas"):
expected = constructor_with_pyarrow(data)
else:
expected = pd.DataFrame(data)

pd.testing.assert_frame_equal(result, expected)

0 comments on commit 46e374b

Please sign in to comment.