Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: define conversion rules #59

Merged
merged 16 commits into from
Jan 25, 2024
Merged

feat: define conversion rules #59

merged 16 commits into from
Jan 25, 2024

Conversation

ianna
Copy link
Member

@ianna ianna commented Jan 23, 2024

restructure to remove weak dependencies: it seems that Python REPL does not allow to see a PythonCall requirement

@ianna ianna marked this pull request as draft January 23, 2024 10:21
Copy link

codecov bot commented Jan 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (ea089c2) 72.03% compared to head (7d2c696) 74.06%.
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #59      +/-   ##
==========================================
+ Coverage   72.03%   74.06%   +2.02%     
==========================================
  Files           4        4              
  Lines        1613     1666      +53     
==========================================
+ Hits         1162     1234      +72     
+ Misses        451      432      -19     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ianna ianna requested a review from Moelf January 24, 2024 14:19
@ianna ianna marked this pull request as ready for review January 24, 2024 14:19
Copy link
Member Author

@ianna ianna left a comment

Choose a reason for hiding this comment

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

@Moelf - Please, have a look when you have time. Thanks!


[extras]
PythonCall = "6099a3de-0909-46bc-b1f4-468b9a2dfc0d"
Copy link
Member Author

Choose a reason for hiding this comment

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

@Moelf - it could be due to my own setup, but I did not manage to get this PythonCall dependency when running from Python REPL. This is an attempt to fix it.

Copy link
Member

Choose a reason for hiding this comment

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

before it was set up in a way such that installing AwkwardArray.jl does NOT imply needing a Python. If I were to do this, I would just make sure from the python side, it calls something to install PythonCall.

The way this PR implements it, you cannot use this package as a pure-Julia package, which may or may not be what you want.

Copy link
Member

Choose a reason for hiding this comment

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

That's what we discussed today. Although it would be better (more opportunities) for this to be usable as a pure-Julia package, @ianna ran into some problems attempting to do so, and I think its primary value would be for users of both Python and Julia. (In Julia, there are already packages for some of these use-cases, such as ArrayOfArrays and StructArrays.)

So the decision between optionally depending on Python and strictly depending on Python is the result of a cost-benefit analysis. The benefit is small but positive; how big is the cost?

Copy link
Member

Choose a reason for hiding this comment

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

the way this PR does it sounds reasonable to me.

function pyconvert_rule_awkward_array_primitive(::Type{AwkwardArray.PrimitiveArray}, x::Py)
array = AwkwardArray.convert(x)
return PythonCall.pyconvert_return(array)
end
Copy link
Member Author

Choose a reason for hiding this comment

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

These rule functions should return pyconvert_unconverted() if the conversion was not possible.

Copy link
Member

@jpivarski jpivarski Jan 24, 2024

Choose a reason for hiding this comment

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

Is that distinct from encountering an Exception and raising it?

For example, in Python, some overloading functions let you return NotImplemented to say, "I'm not handling it; let someone else handle it," but raise XYZ is different.

For Awkward Array conversion, there isn't any Python Awkward Array that would return pyconvert_unconverted() rather than a Julia Awkward Array or vice-versa. But it could encounter an exception in the attempt (e.g. out of memory or recognizing that the array doesn't satisfy a validity rule if the Python Awkward Array was hacked together with __new__ or something).

Copy link
Member Author

Choose a reason for hiding this comment

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

These rule functions should must return pyconvert_unconverted() if the conversion was not possible.

https://github.com/JuliaPy/PythonCall.jl/blob/13f596d6a7d60ef7bfcee2d538cd895f59826d95/src/Convert/pyconvert.jl#L38C1-L45

src/AwkwardPythonCallExt.jl Show resolved Hide resolved
test/runpytests.jl Show resolved Hide resolved
@ianna ianna requested a review from jpivarski January 24, 2024 16:33
Copy link
Member

@jpivarski jpivarski left a comment

Choose a reason for hiding this comment

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

I made some comments below—I should have done it as part of this review—but other than that, this looks good!

We discussed at our meeting that making PythonCall a required dependency is okay. The main benefit of this library is for users of both Python and Julia, since Julia users already have ArrayOfArrays and such. I think the use of this library for Julia only is limited (though not nonexistent).

So I think this is good to merge as-is. There are some open questions (open comment boxes) that @Moelf could help us on, but they're longer-term than this PR.

@ianna ianna merged commit 65e736e into main Jan 25, 2024
5 checks passed
@ianna ianna deleted the ianna/remove_weak_dependencies branch January 25, 2024 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants