Skip to content

Commit a7e41e7

Browse files
authored
Merge pull request #51 from JuliaPy/dotsyntax
Use dot overloading syntax
2 parents cb8dcce + b19532f commit a7e41e7

File tree

4 files changed

+46
-46
lines changed

4 files changed

+46
-46
lines changed

REQUIRE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
julia 0.7
2-
PyCall 1.7.2
2+
PyCall 1.90.0
33
Lazy 0.11.4
44
Compat 0.17
55
IteratorInterfaceExtensions 0.1.1

src/Pandas.jl

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ end
6868
quot(x) = Expr(:quote, x)
6969

7070
function Base.Array(x::PandasWrapped)
71-
c = np[:asarray](x.pyo)
71+
c = np.asarray(x.pyo)
7272
if typeof(c).parameters[1] == PyObject
7373
out = Array{Any}(undef, size(x))
7474
for idx in eachindex(out)
@@ -83,9 +83,9 @@ end
8383

8484
function Base.values(x::PandasWrapped)
8585
# Zero-copy conversion to a Julia native type is possible
86-
x_kind = x.pyo[:dtype][:kind]
86+
x_kind = x.pyo.dtype.kind
8787
if x_kind in ["i", "u", "f", "b"]
88-
pyarray = convert(PyArray, x.pyo["values"])
88+
pyarray = convert(PyArray, x.pyo."values")
8989
unsafe_wrap(Array, pyarray.data, size(pyarray))
9090
else # Convert element by element otherwise
9191
collect(x)
@@ -132,7 +132,7 @@ function pyattr(class, jl_method, py_method)
132132
quote
133133
function $(esc(jl_method))(pyt::$class, args...; kwargs...)
134134
new_args = fix_arg.(args)
135-
method = pyt.pyo[$(string(py_method))]
135+
method = pyt.pyo.$(string(py_method))
136136
pyo = pycall(method, PyObject, new_args...; kwargs...)
137137
wrapped = pandas_wrap(pyo)
138138
end
@@ -169,31 +169,31 @@ macro pyasvec(class)
169169
offset = should_offset(pyt, args...)
170170
new_args = tuple([fix_arg(arg, offset) for arg in args]...)
171171
new_args = (length(new_args)==1 ? new_args[1] : new_args)
172-
pyo = pycall(pyt.pyo[:__getitem__], PyObject, new_args)
172+
pyo = pycall(pyt.pyo.__getitem__, PyObject, new_args)
173173
pandas_wrap(pyo)
174174
end
175175

176176
function $(esc(:setindex!))(pyt::$class, value, idxs...)
177177
offset = should_offset(pyt, idxs...)
178178
new_idx = [fix_arg(idx, offset) for idx in idxs]
179179
if length(new_idx) > 1
180-
pandas_wrap(pycall(pyt.pyo[:__setitem__], PyObject, tuple(new_idx...), value))
180+
pandas_wrap(pycall(pyt.pyo.__setitem__, PyObject, tuple(new_idx...), value))
181181
else
182-
pandas_wrap(pycall(pyt.pyo[:__setitem__], PyObject, new_idx[1], value))
182+
pandas_wrap(pycall(pyt.pyo.__setitem__, PyObject, new_idx[1], value))
183183
end
184184
end
185185
end
186186

187187
if class in [:Iloc, :Loc, :Ix]
188188
length_expr = quote
189189
function $(esc(:length))(x::$class)
190-
x.pyo[:obj][:__len__]()
190+
x.pyo.obj.__len__()
191191
end
192192
end
193193
else
194194
length_expr = quote
195195
function $(esc(:length))(x::$class)
196-
x.pyo[:__len__]()
196+
x.pyo.__len__()
197197
end
198198
end
199199
end
@@ -209,16 +209,16 @@ macro pyasvec(class)
209209
end
210210

211211

212-
@pytype DataFrame ()->pandas_raw[:core][:frame]["DataFrame"]
213-
@pytype Iloc ()->pandas_raw[:core][:indexing]["_iLocIndexer"]
214-
@pytype Loc ()->pandas_raw[:core][:indexing]["_LocIndexer"]
215-
@pytype Ix ()->pandas_raw[:core][:indexing]["_IXIndexer"]
216-
@pytype Series ()->pandas_raw[:core][:series]["Series"]
217-
@pytype MultiIndex ()->pandas_raw[:core][:index]["MultiIndex"]
218-
@pytype Index ()->pandas_raw[:core][:index]["Index"]
219-
@pytype GroupBy ()->pandas_raw[:core][:groupby]["DataFrameGroupBy"]
220-
@pytype SeriesGroupBy ()->pandas_raw[:core][:groupby]["SeriesGroupBy"]
221-
@pytype Rolling () -> pandas_raw[:core][:window]["Rolling"]
212+
@pytype DataFrame ()->pandas_raw.core.frame."DataFrame"
213+
@pytype Iloc ()->pandas_raw.core.indexing."_iLocIndexer"
214+
@pytype Loc ()->pandas_raw.core.indexing."_LocIndexer"
215+
@pytype Ix ()->pandas_raw.core.indexing."_IXIndexer"
216+
@pytype Series ()->pandas_raw.core.series."Series"
217+
@pytype MultiIndex ()->pandas_raw.core.index."MultiIndex"
218+
@pytype Index ()->pandas_raw.core.index."Index"
219+
@pytype GroupBy ()->pandas_raw.core.groupby."DataFrameGroupBy"
220+
@pytype SeriesGroupBy ()->pandas_raw.core.groupby."SeriesGroupBy"
221+
@pytype Rolling () -> pandas_raw.core.window."Rolling"
222222

223223
@pyattr GroupBy app apply
224224
@pyattr Rolling app apply
@@ -246,12 +246,12 @@ pyattr_set([DataFrame, Series], :T, :abs, :align, :any, :argsort, :asfreq, :asof
246246
pyattr_set([DataFrame], :groupby)
247247
pyattr_set([Series, DataFrame], :rolling)
248248

249-
Base.size(x::Union{Loc, Iloc, Ix}) = x.pyo[:obj][:shape]
249+
Base.size(x::Union{Loc, Iloc, Ix}) = x.pyo.obj.shape
250250
Base.size(df::PandasWrapped, i::Integer) = size(df)[i]
251-
Base.size(df::PandasWrapped) = df.pyo[:shape]
251+
Base.size(df::PandasWrapped) = df.pyo.shape
252252

253-
Base.isempty(df::PandasWrapped) = df.pyo[:empty]
254-
Base.empty!(df::PandasWrapped) = df.pyo[:drop](df.pyo[:index], inplace=true)
253+
Base.isempty(df::PandasWrapped) = df.pyo.empty
254+
Base.empty!(df::PandasWrapped) = df.pyo.drop(df.pyo.index, inplace=true)
255255

256256
should_offset(::Any, args...) = false
257257
should_offset(::Union{Iloc, Index}, args...) = true
@@ -267,7 +267,7 @@ end
267267

268268
for attr in [:index, :columns]
269269
@eval function $attr(x::PandasWrapped)
270-
pandas_wrap(x.pyo[$(string(attr))])
270+
pandas_wrap(x.pyo.$(string(attr)))
271271
end
272272
end
273273

@@ -304,7 +304,7 @@ for m in [:read_pickle, :read_csv, :read_html, :read_json, :read_excel, :read_ta
304304
end
305305

306306
function show(io::IO, df::PandasWrapped)
307-
s = df.pyo[:__str__]()
307+
s = df.pyo.__str__()
308308
println(io, s)
309309
end
310310

@@ -328,7 +328,7 @@ end
328328

329329
for m in [:from_arrays, :from_tuples]
330330
@eval function $m(args...; kwargs...)
331-
f = pandas_raw["MultiIndex"][string($(quot(m)))]
331+
f = pandas_raw."MultiIndex"[string($(quot(m)))]
332332
res = pycall(f, PyObject, args...; kwargs...)
333333
pandas_wrap(res)
334334
end
@@ -342,7 +342,7 @@ for (jl_op, py_op, py_opᵒ) in [(:+, :__add__, :__add__), (:*, :__mul__, :__mul
342342
(:&, :__and__, :__and__), (:|, :__or__, :__or__)]
343343
@eval begin
344344
function $(jl_op)(x::PandasWrapped, y)
345-
res = x.pyo[$(string(py_op))](y)
345+
res = x.pyo.$(string(py_op))(y)
346346
pandas_wrap(res)
347347
end
348348

@@ -351,28 +351,28 @@ for (jl_op, py_op, py_opᵒ) in [(:+, :__add__, :__add__), (:*, :__mul__, :__mul
351351
end
352352

353353
function $(jl_op)(y, x::PandasWrapped)
354-
res = x.pyo[$(string(py_opᵒ))](y)
354+
res = x.pyo.$(string(py_opᵒ))(y)
355355
pandas_wrap(res)
356356
end
357357
end
358358
end
359359

360360
for op in [(:-, :__neg__)]
361361
@eval begin
362-
$(op[1])(x::PandasWrapped) = pandas_wrap(x.pyo[$(quot(op[2]))]())
362+
$(op[1])(x::PandasWrapped) = pandas_wrap(x.pyo.$(quot(op[2]))())
363363
end
364364
end
365365

366366
function setcolumns!(df::PandasWrapped, new_columns)
367-
df.pyo[:__setattr__]("columns", new_columns)
367+
df.pyo.__setattr__("columns", new_columns)
368368
end
369369

370370
function deletecolumn!(df::DataFrame, column)
371-
df.pyo[:__delitem__](column)
371+
df.pyo.__delitem__(column)
372372
end
373373

374-
name(s::Series) = s.pyo[:name]
375-
name!(s::Series, name) = s.pyo[:name] = name
374+
name(s::Series) = s.pyo.name
375+
name!(s::Series, name) = s.pyo.name = name
376376

377377
include("operators_v6.jl")
378378

@@ -381,17 +381,17 @@ function DataFrame(pairs::Pair...)
381381
end
382382

383383
function index!(df::PandasWrapped, new_index)
384-
df.pyo[:index] = new_index
384+
df.pyo.index = new_index
385385
df
386386
end
387387

388388
function Base.eltype(s::Series)
389389
dtype_map = Dict(
390-
np[:dtype]("int64") => Int64,
391-
np[:dtype]("float64") => Float64,
392-
np[:dtype]("object") => String,
390+
np.dtype("int64") => Int64,
391+
np.dtype("float64") => Float64,
392+
np.dtype("object") => String,
393393
)
394-
get(dtype_map, s.pyo[:dtype], Any)
394+
get(dtype_map, s.pyo.dtype, Any)
395395
end
396396

397397
function Base.eltype(df::DataFrame)
@@ -411,23 +411,23 @@ function Base.map(f::Function, s::Series)
411411
end
412412

413413
function Base.map(x, s::Series; na_action=nothing)
414-
pandas_wrap(s.pyo[:map](x, na_action))
414+
pandas_wrap(s.pyo.map(x, na_action))
415415
end
416416

417417
function Base.get(df::PandasWrapped, key, default)
418-
pandas_wrap(df.pyo[:get](key, default=default))
418+
pandas_wrap(df.pyo.get(key, default=default))
419419
end
420420

421421
function Base.getindex(s::Series, c::CartesianIndex{1})
422422
s[c[1]]
423423
end
424424

425425
function Base.copy(df::PandasWrapped)
426-
pandas_wrap(df.pyo[:copy]())
426+
pandas_wrap(df.pyo.copy())
427427
end
428428

429429
function !(df::PandasWrapped)
430-
pandas_wrap(df.pyo[:__neg__]())
430+
pandas_wrap(df.pyo.__neg__())
431431
end
432432

433433
include("tabletraits.jl")
@@ -442,7 +442,7 @@ function DataFrame(obj)
442442
end
443443

444444
function has_named_attr(x::Index, s)
445-
return x.pyo[:__contains__](Symbol(s))
445+
return x.pyo.__contains__(Symbol(s))
446446
end
447447

448448
named_index(x::DataFrame) = columns(x)

src/operators_v6.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Base: ==, >, <, >=, <=, !=
22

33
for (op, pyop) in [(:(==), :__eq__), (:>, :__gt__), (:<, :__lt__), (:>=, :__ge__), (:<=, :__le__), (:!=, :__ne__)]
44
@eval function Base.broadcast(::typeof($op), s::PandasWrapped, x)
5-
method = s.pyo[$(QuoteNode(pyop))]
5+
method = s.pyo.$(QuoteNode(pyop))
66
pandas_wrap(pycall(method, PyObject, x))
77
end
88
end

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ using Pandas
22
using Test
33

44
df = DataFrame(Dict(:name=>["a", "b"], :age=>[27, 30]))
5-
age = values(df[:age])
5+
age = values(df.age)
66
age[2] = 31
77
@test loc(df)[1, "age"] == 31
88

0 commit comments

Comments
 (0)