Skip to content

Commit 902e9b0

Browse files
committed
Make 'values' work on dataframes.
1 parent 8f7e475 commit 902e9b0

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/Pandas.jl

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,17 @@ end
110110

111111

112112
function Base.values(x::PandasWrapped)
113-
# Zero-copy conversion to a Julia native type is possible
114-
x_kind = x.pyo.dtype.kind
115-
if x_kind in ["i", "u", "f", "b"]
116-
pyarray = convert(PyArray, x.pyo."values")
117-
unsafe_wrap(Array, pyarray.data, size(pyarray))
118-
else # Convert element by element otherwise
119-
collect(x)
113+
# Check if zero-copy conversion to a Julia native type
114+
# is possible.
115+
if hasproperty(x.pyo, :dtype)
116+
x_kind = x.pyo.dtype.kind
117+
if x_kind in ["i", "u", "f", "b"]
118+
pyarray = convert(PyArray, x.pyo."values")
119+
return unsafe_wrap(Array, pyarray.data, size(pyarray))
120+
end
120121
end
122+
# Convert element by element otherwise
123+
Array(x)
121124
end
122125

123126
"""

test/runtests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,7 @@ df3 = Pandas.Series(3:4)
8181
@test all(df1 == df1)
8282
@test all(df1 == df2)
8383
@test df1 != [1, 2]
84+
85+
# Issue #93
86+
df = DataFrame(:a=>[1,2], :b=>[4,5], :c=>["a","b"])
87+
@test values(df) == [1 4 "a"; 2 5 "b"]

0 commit comments

Comments
 (0)