Skip to content

Commit

Permalink
Merge pull request #18 from CarloLucibello/cl/pil
Browse files Browse the repository at this point in the history
fix for PIL imports + fix DatasetDict julia format
  • Loading branch information
CarloLucibello authored May 23, 2023
2 parents 10e307a + 204da15 commit 9088490
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 14 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ jobs:
fail-fast: false
matrix:
version:
- '1.7'
- '1'
- '1.9'
# - '1' # add back when 1.10 is out
- 'nightly'
os:
- ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/TagBot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
# Edit the following line to reflect the actual name of the GitHub Secret containing your private key
ssh: ${{ secrets.DOCUMENTER_KEY }}
# ssh: ${{ secrets.NAME_OF_MY_SSH_PRIVATE_KEY_SECRET }}
# ssh: ${{ secrets.NAME_OF_MY_SSH_PRIVATE_KEY_SECRET }}
10 changes: 6 additions & 4 deletions CondaPkg.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
channels = ["conda-forge"]

[deps]
h5py = ""
pillow = ">=9.1, <10"
# h5py = ""
# pillow = ">=9.1, <10"
# pyarrow = "==6.0.0"
datasets = ">=2.12, <3"
numpy = ">=1.20, <2"
datasets = ">=2.7, <3"
pyarrow = "==6.0.0"
pillow = ""

4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "HuggingFaceDatasets"
uuid = "d94b9a45-fdf5-4270-b024-5cbb9ef7117d"
authors = ["Carlo Lucibello"]
version = "0.3.0"
version = "0.3.1"

[deps]
CondaPkg = "992eb4ea-22a4-4c89-a5bb-47a3300528ab"
Expand All @@ -16,7 +16,7 @@ DLPack = "0.1"
ImageCore = "0.9"
MLUtils = "0.4.1"
PythonCall = "0.9"
julia = "1.7"
julia = "1.9"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
2 changes: 2 additions & 0 deletions src/HuggingFaceDatasets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ function __init__()
# https://cjdoris.github.io/PythonCall.jl/dev/pythoncall-reference/#PythonCall.pycopy!
PythonCall.pycopy!(datasets, pyimport("datasets"))
PythonCall.pycopy!(PIL, pyimport("PIL"))
pyimport("PIL.PngImagePlugin")
pyimport("PIL.JpegImagePlugin")
PythonCall.pycopy!(np, pyimport("numpy"))
PythonCall.pycopy!(copy, pyimport("copy"))
end
Expand Down
2 changes: 1 addition & 1 deletion src/dataset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ version of [`with_format`](@ref).
"""
function set_format!(ds::Dataset, format)
if format == "julia"
# ds.pyds.set_format("numpy")
ds.pyds.reset_format() # or d.pyd.set_format("python")
ds.jltransform = py2jl
else
ds.pyds.set_format(format)
Expand Down
2 changes: 1 addition & 1 deletion src/datasetdict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ version of [`with_format`](@ref).
"""
function set_format!(d::DatasetDict, format)
if format == "julia"
d.pyd.set_format("numpy")
d.pyd.reset_format()
d.jltransform = py2jl
else
d.pyd.set_format(format)
Expand Down
2 changes: 2 additions & 0 deletions src/transforms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function _pyconvert(x::Py)
end
end

# Do nothing on a non-Py object.
_pyconvert(x) = x

"""
Expand All @@ -30,6 +31,7 @@ Convert Python types to Julia types applying `pyconvert` recursively.
"""
py2jl

# py2jl recurses through pycanonicalize and converts through _pyconvert
py2jl(x) = pycanonicalize(_pyconvert(x))

pycanonicalize(x) = x
Expand Down
1 change: 0 additions & 1 deletion test/dataset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ end
@test x isa Dict
@test x["label"] == -1
@test x["idx"] == 0
@show x["premise"] |> typeof
@test x["premise"] isa AbstractString
@test x["premise"] == "The cat sat on the mat."
@test x["hypothesis"] isa AbstractString
Expand Down
4 changes: 2 additions & 2 deletions test/datasetdict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ end
@testset "with_format(julia)" begin
d = with_format(mnist, "julia")
ds = d["test"]
@test ds.format["type"] == "numpy"
@test ds.format["type"] == nothing
x = ds[1]
@test x isa Dict
@test x["label"] isa Int
@test x["label"] == 7
@test x["image"] isa Matrix{UInt8}
@test x["image"] isa AbstractMatrix{<:Gray}
@test size(x["image"]) == (28, 28)
end

Expand Down

2 comments on commit 9088490

@CarloLucibello
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/84061

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.1 -m "<description of version>" 9088490aba4ff437fa41dea89a04868f11eebce3
git push origin v0.3.1

Please sign in to comment.