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

[Python] Array sort functions not implemented #3638

Closed
HLWeil opened this issue Dec 3, 2023 · 2 comments · Fixed by #3651
Closed

[Python] Array sort functions not implemented #3638

HLWeil opened this issue Dec 3, 2023 · 2 comments · Fixed by #3651
Assignees

Comments

@HLWeil
Copy link

HLWeil commented Dec 3, 2023

Description

Array sorting functions fail.

Repro code

test.fsx

Array.sort [|3;2;4|]
Array.sortDescending [|3;2;4|]

test.cmd

dotnet fable . --lang python
python test.py

Expected and actual results

Expected result: should return sorted arrays

Actual result: AttributeError: 'array.array' object has no attribute 'sort'

Related information

  • dotnet fable --version: 4.5.0
  • dotnet tool list/update/install: 4.6.0
  • Windows11

@Freymaurer

@dbrattli
Copy link
Collaborator

dbrattli commented Dec 8, 2023

Yes, there's quite a few functions not working with arrays. May I ask what use-case you have for arrays? I'm a bit unsure what to do with arrays for Fable Python. Currently they transpile to bytearray (uint8), list (generic) or array.array (everything else) depending on the type. But this makes it hard to add functions that works across all the types. I see pyodide translates to lists for js arrays, but using only likes makes interop with libraries that needs bytes or bytearrays (networking libraries etc). One option is to use numpy arrays, but then we require quite a large dependency (and there might be version conflicts with the user is already using a different version of numpy). Any suggestions or thouhts?

@HLWeil
Copy link
Author

HLWeil commented Dec 9, 2023

@dbrattli thank you for your reply and your efforts in general!

I see, that sounds like a really tricky problem to solve. I think in my case it's technically not really a special case. We are comparing the values of two dictionaries. But as they are basically randomly sorted in .NET, we first sort by the keys.

My first naive intuition would be to try to create a very low level API for functionality on all of the types you mentioned and put the functions like sort on top. Unfortunately, I can't offer any opinion on the specific types and libraries you mentioned, as my Python knowlegde is mostly stemming from my interaction with Fable 😅.

For now, I'll make due with

    let sort (a : 'T []) = 
     #if FABLE_COMPILER_PYTHON
         a |> List.ofArray |> List.sort |> Array.ofList       
     #else
         a |> Array.sort
     #endif

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 a pull request may close this issue.

2 participants