Skip to content

Commit

Permalink
Merge pull request #81 from yuehhua/pickle
Browse files Browse the repository at this point in the history
Use Pickle in favor of PyCall
  • Loading branch information
yuehhua authored Nov 27, 2021
2 parents d184e5c + b124a43 commit c324396
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/UnitTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
julia-version: ['1.0', '1', 'nightly']
julia-version: ['1.3', '1', 'nightly']
os: [ubuntu-latest, windows-latest, macOS-latest]
env:
PYTHON: ""
Expand Down
7 changes: 4 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ FixedPointNumbers = "53c48c17-4a7d-5ca2-90c5-79b7896eea93"
GZip = "92fee26a-97fe-5a0c-ad85-20a5f3185b63"
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
MAT = "23992714-dd62-5051-b70f-ba57cb901cac"
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
Pickle = "fbb45041-c46e-462f-888f-7c521cafbc2c"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[compat]
BinDeps = "1"
Expand All @@ -23,9 +24,9 @@ GZip = "0.5"
ImageCore = "0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8"
JSON3 = "1"
MAT = "0.7, 0.8, 0.9, 0.10"
PyCall = "1"
Pickle = "0.2"
Requires = "1"
julia = "1"
julia = "1.3"

[extras]
ImageCore = "a09fc81d-aa75-5fe9-8630-4744c3626534"
Expand Down
2 changes: 0 additions & 2 deletions src/CiteSeer/CiteSeer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ using DataDeps
using ..MLDatasets: datafile, read_planetoid_data
using DelimitedFiles: readdlm

using PyCall

const DEPNAME = "CiteSeer"
const LINK = "https://github.com/kimiyoung/planetoid/raw/master/data"
const DOCS = "https://github.com/kimiyoung/planetoid"
Expand Down
2 changes: 0 additions & 2 deletions src/Cora/Cora.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ using DataDeps
using ..MLDatasets: datafile, read_planetoid_data
using DelimitedFiles: readdlm

using PyCall

const DEPNAME = "Cora"
# LINK = "https://github.com/shchur/gnn-benchmark/raw/master/data/npz"
# LINK = "https://github.com/abojchevski/graph2gauss/raw/master/data/"
Expand Down
17 changes: 2 additions & 15 deletions src/MLDatasets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ using ColorTypes: length
using Requires
using DelimitedFiles: readdlm
using FixedPointNumbers, ColorTypes
using PyCall
using Pickle
using SparseArrays

# Julia 1.0 compatibility
if !isdefined(Base, :isnothing)
Expand Down Expand Up @@ -67,20 +68,6 @@ function __init__()
global __images_supported__ = true
end

# install scipy if not already there
pyimport_conda("scipy", "scipy")

py"""
import pickle
def pyread_planetoid_file(path, name):
out = pickle.load(open(path, "rb"), encoding="latin1")
if name == 'graph':
return out
out = out.todense() if hasattr(out, 'todense') else out
return out
"""

__init__tudataset()
end

Expand Down
2 changes: 0 additions & 2 deletions src/PubMed/PubMed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ using DataDeps
using ..MLDatasets: datafile, read_planetoid_data
using DelimitedFiles: readdlm

using PyCall

const DEPNAME = "PubMed"
const LINK = "https://github.com/kimiyoung/planetoid/raw/master/data"
const DOCS = "https://github.com/kimiyoung/planetoid"
Expand Down
2 changes: 1 addition & 1 deletion src/TUDataset/TUDataset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function __init__tudataset()
Website: $LINK)
""",
"$LINK/$DATA",
# "81de017067dc045ebdb8ffd5c0e69a209973ffdb1fe2d5b434e94d3614f3f5c7", # if checksum omitted, will be generated by DataDeps
"2da8de15284b88edabca2888ce5444d62f364ed41159260977088c4e53d4d848", # if checksum omitted, will be generated by DataDeps
post_fetch_method = unpack
))
end
Expand Down
13 changes: 12 additions & 1 deletion src/planetoid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,23 @@ function read_planetoid_data(DEPNAME; dir=nothing, reverse_edges=true)
directed = reverse_edges != true)
end

function read_pickle_file(filename, name)
out = Pickle.npyload(filename)
if name == "graph"
return out
end
if out isa SparseMatrixCSC
return Matrix(out)
end
return out
end

function read_planetoid_file(DEPNAME, name, dir)
filename = datafile(DEPNAME, name, dir)
if endswith(name, "test.index")
out = 1 .+ vec(readdlm(filename, Int))
else
out = py"pyread_planetoid_file"(filename, name)
out = read_pickle_file(filename, name)
if out isa Matrix
out = collect(out')
end
Expand Down

0 comments on commit c324396

Please sign in to comment.