You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.
Hello, i would like to show the results i obtained using pyrs together with monkeytype and the process i followed.
These are the first commands i used:
cd typing
echo'layout python3'> .envrc
direnv allow
git clone https://github.com/chonyy/fpgrowth_py.git
git clone https://github.com/Instagram/MonkeyType.git
git clone https://github.com/konchunas/pyrs.git
cd MonkeyType
python3 -m pip install -e .cd ../fpgrowth_py
monkeytype run run.py
monkeytype list-modules # optional step that shows what `apply` accepts
monkeytype apply fpgrowth_py.utils
git clone https://github.com/chonyy/fpgrowth_py.git is here the project that is being converted but it might be any project.
After that i ran
monkeytype apply fpgrowth_py.fpgrowth
But i ran into a problem
File "/home/flip111/typing/fpgrowth_py/fpgrowth_py/utils.py", line 7, in Node
def __init__(self, itemName: str, frequency: int, parentNode: Optional[Node]) -> None:
NameError: name 'Node' is not defined
I solved this by temporarily removing the type definition part : Optional[Node], then running monkeytype again and then putting the type definition back.
got translated into (i indented this for convenience of reading this post)
fngetFromFile<T0,RT>(fname:T0) -> RT{letmut itemSetList = vec![];letmut frequency = vec![];// with!(open(fname, "r") as file) //unsupported{let csv_reader = reader(file);}for line in csv_reader {
line = line.into_iter().filter(None).collect::<Vec<_>>();
itemSetList.push(line);
frequency.push(1);}}return(itemSetList, frequency);}
There is the unsupported with language construct together with a file open. Also one closing bracket got introduced after let csv_reader = reader(file); for some reason. I manually fixed this into
fngetFromFile<T0,RT>(fname:T0) -> RT{letmut itemSetList = vec![];letmut frequency = vec![];// with!(open(fname, "r") as file) //unsupportedifletOk(file) = std::fs::File::open(fname){let csv_reader = reader(file);for line in csv_reader {
line = line.into_iter().filter(None).collect::<Vec<_>>();
itemSetList.push(line);
frequency.push(1);}}return(itemSetList, frequency);}
I previously ran this process without the monkeytype step. After this i was able to make a diff of the resulting rust source code. Here is a diff of the pygrowth.rs file which shows also in Rust there are a lot more concrete types available
After this i copied the two new source files into a new project
cargo new fpgrowth_rs
cp fpgrowth_py/fpgrowth_py/fpgrowth.rs fpgrowth_rs/src
cp fpgrowth_py/fpgrowth_py/utils.rs fpgrowth_rs/src
cd fpgrowth_rs
I added an import for fpgrowth into src/main.rs
mod fpgrowth;fnmain(){println!("Hello, world!");}
I then tried to fix the source files with clippy
cargo clippy --fix --allow-dirty
Clippy reported the following errors
» cargo clippy --fix --allow-dirty
Checking fpgrowth_rs v0.1.0 (/home/flip111/typing/fpgrowth_rs)
error[E0433]: failed to resolve: use of undeclared crate or module `fpgrowth_py`
--> src/fpgrowth.rs:6:5
|
6 | use fpgrowth_py::utils::*;
| ^^^^^^^^^^^ use of undeclared crate or module `fpgrowth_py`
|
help: there is a crate or module with a similar name
|
6 | use fpgrowth::utils::*;
| ~~~~~~~~
error[E0432]: unresolved imports `collections::defaultdict`, `collections::OrderedDict`
--> src/fpgrowth.rs:4:19
|
4 | use collections::{defaultdict, OrderedDict};
| ^^^^^^^^^^^ ^^^^^^^^^^^ no `OrderedDict` in `collections`
| |
| no `defaultdict` in `collections`
error[E0432]: unresolved import `csv`
--> src/fpgrowth.rs:5:5
|
5 | use csv::reader;
| ^^^ use of undeclared crate or module `csv`
error[E0432]: unresolved import `itertools`
--> src/fpgrowth.rs:7:5
|
7 | use itertools::{chain, combinations};
| ^^^^^^^^^ use of undeclared crate or module `itertools`
error[E0432]: unresolved import `optparse`
--> src/fpgrowth.rs:8:5
|
8 | use optparse::OptionParser;
| ^^^^^^^^ use of undeclared crate or module `optparse`
error[E0412]: cannot find type `Set` in this scope
--> src/fpgrowth.rs:14:11
|
14 | ) -> (Vec<Set<&str>>, Vec<Vec<Union<Set<&str>, f32>>>) {
| ^^^ not found in this scope
error[E0412]: cannot find type `Union` in this scope
--> src/fpgrowth.rs:14:31
|
14 | ) -> (Vec<Set<&str>>, Vec<Vec<Union<Set<&str>, f32>>>) {
| ^^^^^ not found in this scope
|
help: consider importing one of these items
|
1 | use crate::fpgrowth::collections::btree_set::Union;
|
1 | use crate::fpgrowth::collections::hash_set::Union;
|
1 | use std::collections::btree_set::Union;
|
1 | use std::collections::hash_set::Union;
|
error[E0412]: cannot find type `Set` in this scope
--> src/fpgrowth.rs:14:37
|
14 | ) -> (Vec<Set<&str>>, Vec<Vec<Union<Set<&str>, f32>>>) {
| ^^^ not found in this scope
error[E0425]: cannot find function `getFrequencyFromList` in this scope
--> src/fpgrowth.rs:15:21
|
15 | let frequency = getFrequencyFromList(itemSetList);
| ^^^^^^^^^^^^^^^^^^^^ not found in this scope
error[E0425]: cannot find function `constructTree` in this scope
--> src/fpgrowth.rs:17:33
|
17 | let (fpTree, headerTable) = constructTree(itemSetList, frequency, minSup);
| ^^^^^^^^^^^^^ not found in this scope
error[E0425]: cannot find function `mineTree` in this scope
--> src/fpgrowth.rs:22:9
|
22 | mineTree(headerTable, minSup, set(), freqItems);
| ^^^^^^^^ not found in this scope
error[E0425]: cannot find function `set` in this scope
--> src/fpgrowth.rs:22:39
|
22 | mineTree(headerTable, minSup, set(), freqItems);
| ^^^ not found in this scope
error[E0425]: cannot find function `associationRule` in this scope
--> src/fpgrowth.rs:23:21
|
23 | let rules = associationRule(freqItems, itemSetList, minConf);
| ^^^^^^^^^^^^^^^ not found in this scope
error[E0425]: cannot find function `getFromFile` in this scope
--> src/fpgrowth.rs:28:36
|
28 | let (itemSetList, frequency) = getFromFile(fname);
| ^^^^^^^^^^^ not found in this scope
error[E0425]: cannot find function `constructTree` in this scope
--> src/fpgrowth.rs:30:33
|
30 | let (fpTree, headerTable) = constructTree(itemSetList, frequency, minSup);
| ^^^^^^^^^^^^^ not found in this scope
error[E0425]: cannot find function `mineTree` in this scope
--> src/fpgrowth.rs:35:9
|
35 | mineTree(headerTable, minSup, set(), freqItems);
| ^^^^^^^^ not found in this scope
error[E0425]: cannot find function `set` in this scope
--> src/fpgrowth.rs:35:39
|
35 | mineTree(headerTable, minSup, set(), freqItems);
| ^^^ not found in this scope
error[E0425]: cannot find function `associationRule` in this scope
--> src/fpgrowth.rs:36:21
|
36 | let rules = associationRule(freqItems, itemSetList, minConf);
| ^^^^^^^^^^^^^^^ not found in this scope
warning: unused import: `std::collections::HashMap`
--> src/fpgrowth.rs:1:5
|
1 | use std::collections::HashMap;
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
warning: unnecessary parentheses around assigned value
--> src/fpgrowth.rs:16:18
|
16 | let minSup = (itemSetList.len() * minSupRatio);
| ^ ^
|
= note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
|
16 - let minSup = (itemSetList.len() * minSupRatio);
16 + let minSup = itemSetList.len() * minSupRatio;
|
warning: unnecessary parentheses around assigned value
--> src/fpgrowth.rs:29:18
|
29 | let minSup = (itemSetList.len() * minSupRatio);
| ^ ^
|
help: remove these parentheses
|
29 - let minSup = (itemSetList.len() * minSupRatio);
29 + let minSup = itemSetList.len() * minSupRatio;
|
error[E0277]: cannot multiply `usize` by `f32`
--> src/fpgrowth.rs:16:37
|
16 | let minSup = (itemSetList.len() * minSupRatio);
| ^ no implementation for `usize * f32`
|
= help: the trait `std::ops::Mul<f32>` is not implemented for `usize`
error[E0308]: mismatched types
--> src/fpgrowth.rs:31:23
|
27 | fn fpgrowthFromFile<T0, T1, T2, RT>(fname: T0, minSupRatio: T1, minConf: T2) -> RT {
| -- this type parameter
...
31 | if fpTree == None {
| _______________________^
32 | | println!("{:?} ", "No frequent item set");
33 | | } else {
| |_____^ expected type parameter `RT`, found `()`
|
= note: expected type parameter `RT`
found unit type `()`
error[E0308]: mismatched types
--> src/fpgrowth.rs:37:16
|
27 | fn fpgrowthFromFile<T0, T1, T2, RT>(fname: T0, minSupRatio: T1, minConf: T2) -> RT {
| -- this type parameter -- expected `RT` because of return type
...
37 | return (freqItems, rules);
| ^^^^^^^^^^^^^^^^^^ expected type parameter `RT`, found tuple
|
= note: expected type parameter `RT`
found tuple `(std::vec::Vec<_>, _)`
Some errors have detailed explanations: E0277, E0308, E0412, E0425, E0432, E0433.
For more information about an error, try `rustc --explain E0277`.
warning: `fpgrowth_rs` (bin "fpgrowth_rs" test) generated 3 warnings
error: could not compile `fpgrowth_rs` due to 21 previous errors; 3 warnings emitted
warning: build failed, waiting for other jobs to finish...
warning: `fpgrowth_rs` (bin "fpgrowth_rs") generated 3 warnings (3 duplicates)
error: build failed
I have yet to inspect these errors and figure out whether they best be fixed before or after using pyrs
Hello, i would like to show the results i obtained using pyrs together with monkeytype and the process i followed.
These are the first commands i used:
git clone https://github.com/chonyy/fpgrowth_py.git
is here the project that is being converted but it might be any project.After that i ran
But i ran into a problem
I solved this by temporarily removing the type definition part
: Optional[Node]
, then running monkeytype again and then putting the type definition back.After that it was time for pyrs
rustfmt
then complainsBecause python source code
got translated into (i indented this for convenience of reading this post)
There is the unsupported
with
language construct together with a file open. Also one closing bracket got introduced afterlet csv_reader = reader(file);
for some reason. I manually fixed this intoI previously ran this process without the monkeytype step. After this i was able to make a diff of the resulting rust source code. Here is a diff of the
pygrowth.rs
file which shows also in Rust there are a lot more concrete types availableAfter this i copied the two new source files into a new project
cargo new fpgrowth_rs cp fpgrowth_py/fpgrowth_py/fpgrowth.rs fpgrowth_rs/src cp fpgrowth_py/fpgrowth_py/utils.rs fpgrowth_rs/src cd fpgrowth_rs
I added an import for fpgrowth into
src/main.rs
I then tried to fix the source files with clippy
Clippy reported the following errors
I have yet to inspect these errors and figure out whether they best be fixed before or after using pyrs
Conclusion:
itertools
don't yet get translated to their rust equivelantThe text was updated successfully, but these errors were encountered: