Julia is giving me the following error: Failed to precompile ExcelFiles - excel

this is my first time using Julia on Visual Studio. I am running a code and it gives me this error:
ERROR: Failed to precompile ExcelFiles [89b67f3b-d1aa-5f6f-9ca4-282e8d98620d] to C:\Users\hcardenas.julia\compiled\v1.8\ExcelFiles\jl_CB4D.tmp.
Stacktrace:
error(s::String) at .\error.jl
compilecache(pkg::Base.PkgId, path::String, internal_stderr::IO, internal_stdout::IO, keep_loaded_modules::Bool) at .\loading.jl
compilecache at .\loading.jl
_require(pkg::Base.PkgId) at .\loading.jl
_require_prelocked(uuidkey::Base.PkgId) at .\loading.jl
macro expansion at .\loading.jl
macro expansion at .\lock.jl
require(into::Module, mod::Symbol) at .\loading.jl
eval at .\boot.jl
include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String) at .\loading.jl
invokelatest(::Any, ::Any, ::Vararg{Any}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}) at .\essentials.jl
invokelatest(::Any, ::Any, ::Vararg{Any}) at .\essentials.jl
inlineeval(m::Module, code::String, code_line::Int64, code_column::Int64, file::String; softscope::Bool) at c:\Users\hcardenas.vscode\extensions\julialang.language-julia-1.38.2\scripts\packages\VSCodeServer\src\eval.jl
(::VSCodeServer.var"#66#70"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})() at c:\Users\hcardenas.vscode\extensions\julialang.language-julia-1.38.2\scripts\packages\VSCodeServer\src\eval.jl
withpath(f::VSCodeServer.var"#66#70"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams}, path::String) at c:\Users\hcardenas.vscode\extensions\julialang.language-julia-1.38.2\scripts\packages\VSCodeServer\src\repl.jl
(::VSCodeServer.var"#65#69"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})() at c:\Users\hcardenas.vscode\extensions\julialang.language-julia-1.38.2\scripts\packages\VSCodeServer\src\eval.jl
hideprompt(f::VSCodeServer.var"#65#69"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams}) at c:\Users\hcardenas.vscode\extensions\julialang.language-julia-1.38.2\scripts\packages\VSCodeServer\src\repl.jl
(::VSCodeServer.var"#64#68"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})() at c:\Users\hcardenas.vscode\extensions\julialang.language-julia-1.38.2\scripts\packages\VSCodeServer\src\eval.jl
with_logstate(f::Function, logstate::Any) at .\logging.jl
with_logger at .\logging.jl
(::VSCodeServer.var"#63#67"{VSCodeServer.ReplRunCodeRequestParams})() at c:\Users\hcardenas.vscode\extensions\julialang.language-julia-1.38.2\scripts\packages\VSCodeServer\src\eval.jl
#invokelatest#2 at .\essentials.jl
invokelatest(::Any) at .\essentials.jl
macro expansion at c:\Users\hcardenas.vscode\extensions\julialang.language-julia-1.38.2\scripts\packages\VSCodeServer\src\eval.jl
(::VSCodeServer.var"#61#62")() at .\task.jl
Can anyone help me? Thank you

Related

How to annotate attrs field with validator?

I am having trouble annotating attrs class attribute.
I am using NewType for defining new UserId type and attrs frozen classes.
This is code where mypy doesn't complain and everything is alright:
from typing import NewType
from attr import frozen, field
UserId = NewType("UserId", str)
#frozen
class Order:
id: UserId = field()
mypy does not have any issues when checking this code.
The problem appears after using validators from attrs.
from typing import NewType
from attr import frozen, field, validators
UserId = NewType("UserId", str)
#frozen
class Order:
id: UserId = field(validator=validators.matches_re("^\d+$"))
mypy now complains about incorrect types:
project/test_annotation.py:10: error: Incompatible types in assignment
(expression has type "str", variable has type "UserId") [assignment]
Found 1 error in 1 file (checked 1 source file)
I don't understand how field() returns string type right now.
Can somebody explain that? Also, how can we work around this problem?
env:
Python 3.10.6
attrs==22.1.0
cattrs==22.2.0
To make it happy, cast. field is considerably complicated, your field returns a str thanks to this overload:
... # other overloads
# This form catches an explicit None or no default and infers the type from the
# other arguments.
#overload
def field(
*,
default: None = ...,
validator: Optional[_ValidatorArgType[_T]] = ...,
repr: _ReprArgType = ...,
hash: Optional[bool] = ...,
init: bool = ...,
metadata: Optional[Mapping[Any, Any]] = ...,
converter: Optional[_ConverterType] = ...,
factory: Optional[Callable[[], _T]] = ...,
kw_only: bool = ...,
eq: Optional[_EqOrderType] = ...,
order: Optional[_EqOrderType] = ...,
on_setattr: Optional[_OnSetAttrArgType] = ...,
alias: Optional[str] = ...,
) -> _T: ...
It basically says "when validators is a [sequence of or one of] validators working on some type T, then field returns T".
So, you pass a validator that works on str, and thus field type is str as well. NewType("UserID", str) is not a subtype of str, so this assignment fails. You have two major options:
cast to desired type:
from typing import cast
...
#frozen
class Order:
id: UserId = cast(str, field(validator=validators.matches_re("^\d+$")))
create your own validator. You don't need to replicate the logic, only change the signature and call original implementation with type: ignore or casts.
from typing import TYPE_CHECKING, Callable, Match, Optional, Pattern, Union, cast
if TYPE_CHECKING:
from attr import _ValidatorType
def userid_matches_re(
regex: Union[Pattern[str], str],
flags: int = ...,
func: Optional[
Callable[[str, str, int], Optional[Match[str]]]
] = ...,
) -> '_ValidatorType[UserID]':
return cast('_ValidatorType[UserID]', validators.matches_re(regex, flags, func))
... and use it in your class instead of validators.matches_re. The signature above is stolen from stubs with AnyStr replaced with str, because you don't allow bytes anyway.
I'd recommend the first variant, because another solution is just more boilerplate with the same cast as a result, it gives you no more safety. However, it may be viable if you have many fields with this validator.

Pair RDD with Array Values

I'm new to Spark. Trying to flatten the RDD from the below format.
rdd=((key),((value1,value2),Some((value3,value4))))
to
(key,value1,value2,value3,value4)
tried to map the values as below. with case class
case class outdata(Key: String, Value1: String, Value2: String, Value3:String, Value4:String)
rdd.map{case(x,y)=>outdata(x_.1,y._1._1,y._1._2,y._2._1,y._2._2)}
getting error y._2._1 is not member
Scala's pattern matching is expressive enough to do this without a case class:
rdd.map{case (key : String, ((value1 : String, value2: String), Some((value3 : String, value4 : String)))) => (key, value1, value2, value3, value4) }

Expression of Type Scala.Predef.String doesn't conform to expected type String

I have a function, validateCell, that takes a function, func, as one of its input parameters. It is as follows:
def validateCell[String](cellKey: String, cell: Option[String], func:(String) => Boolean): Tuple2[Boolean, String] = {
cell match {
case Some(cellContents) => (func(cellContents), s"$cellContents is not valid.")
case None => (false, s"$cellKey, not found.")
}
}
I call the function as follows:
val map = Map("Well" -> "A110")
validateCell("Well", map.get("Well"), BarcodeWell.isValidWell)
The function that is passed in this case is as follows, though I don't think it's related to the problem:
def isValidWell(w: String): Boolean = {
val row: String = w.replaceAll("[^A-Za-z]", "")
val col: Int = w.replaceAll("[^0-9]+", "").toInt
isValidRow(row) && isValidColumn(col)
}
I am expecting validateCell to return a Tuple(Boolean, String), but I get the following error:
Error:(5, 55) type mismatch;
found : java.lang.String
required: String(in method validateCell)
case Some(cellContents) => (func(cellContents), s"$cellContents is not valid.")
I can make this error go away by converting the java strings in each tuple that are returned by the case statements to Scala strings like so:
s"$cellContents is not valid.".asInstanceOf[String]
s"$cellKey, not found.".asInstanceOf[String]
This seems really silly. What am I missing here? Shouldn't this conversion be handled by Scala automatically and why are my strings being cast as Java strings in the first place?
There is no difference between Scala strings and Java strings. In fact, Predef.String aliases to java.lang.String. However, you're working with neither of these things; you're working with a type parameter.
def validateCell[String](cellKey: String, cell: Option[String], func:(String) => Boolean): Tuple2[Boolean, String] = {
This is a generic function which takes a type argument whose name is String. When you call validateCell, this type argument is being inferred and filled in for you, by something that definitely isn't a string. My guess is that you're misunderstanding the point of the brackets and that you meant to write
def validateCell(cellKey: String, cell: Option[String], func:(String) => Boolean): Tuple2[Boolean, String] = {

Kotlin - Type mismatch: Required: String, Found: () -> String

In Kotlin I declared a List<String> like this:
private val items = listOf<String> {
"String1",
"String2",
"String3"
}
the compiler is giving me this error:
Type Mismatch.
Required: String
Found: () -> String
What does it mean? How do I fix it?
P.S. Pretty new to Kotlin so bear with me for asking something obvious.
You passed the argument enclosed in {} which introduced a function literal (lambda) which is why the compiler finds a function type
Found: () -> String
Instead just use parentheses like this:
listOf("String1", "String2")
Some information:
Kotlin allows you to pass functions after the () when passed as the last argument. The parentheses can be left away if the function is the only argument as in your example. Therefore the code is valid but simply does not match the function parameter type.
Try this:
private val items = listOf("String1", "String2", "String3")
I had this problem trying to add headers to retrofit in Kotlin.
Java Code was:
#Headers({"Accept: application/json",
"userName: blah#test.com"
})
It turns out the solution was not listOf or arrayOf, but to just remove the {}
Kotlin Solution:
#Headers("Accept: application/json",
"userName: blah#test.com"
)
Reference: https://github.com/square/retrofit/issues/2518

Alloy signatures not shown in Alloy Analyzer 4.2

I have to use Alloy in a Requirements Analysis and Specification Document for a university project. I started with the easy stuff, only signatures and no facts. These are the signatures I use:
abstract sig Date{
year: one Int,
month: one Int,
day: one Int
}
abstract sig Time{
h: one Int,
m: one Int,
s: one Int
}
abstract sig Double{
leftPart: one Int,
rightPart: one Int
}
abstract sig Bool{
value: one String
}
sig DateBirth extends Date{}
sig DateRide extends Date{}
sig DateExpiry extends Date{}
abstract sig User {
email: one String,
name: one String,
surname: one String,
gender: one Bool,
address: one String,
password: one String,
dateOfBirth: one DateBirth,
IDRide: set Ride
}
sig TaxiDriver extends User{
taxiLicense: one String,
personalLicense: one String,
IBAN: one String,
positionInQueue: lone Int,
IDTaxi: set Taxi
}
sig Client extends User{
}
sig Zone {
numberOfZone: one Int,
vertexNorthWest: one Double,
vertexNorthEast: one Double,
vertexSouthWest: one Double,
vertexSouthEast: one Double,
currentQueue: set TaxiDriver
}
sig Taxi {
IDTaxi: one String,
plate: one String,
availablePlaces: one Int,
}
sig Ride {
IDRide: one String,
origin: one String,
destination: one String,
dateOfRide: one DateRide,
timeOfDeparture: one Time,
timeOfArrival: one Time,
price: one Double,
numberOfPeople: one Int,
accepted: one Bool,
userEmail: set User
}
sig Credit_Card {
number: Double,
owner: String,
expiryDate: DateExpiry,
ownerEmail: one Client
}
Then, I added the predicate "show" to veify whether the it is consistent or not:
pred Show{}
run Show for 10
After running "Execute" on Alloy Analyzer 4.2 this is the message I get:
Executing "Run Show for 10"
Solver=sat4j Bitwidth=4 MaxSeq=7 SkolemDepth=1 Symmetry=20
21067 vars. 3840 primary vars. 37164 clauses. 376ms.
Instance. found. Predicate is consistent. 375ms.
No problems, right? But then, when I click on "Show" there are no instances of the signature "User" (and its child signatures) shown on the display, while all the others are there. I tried to click on "Next" a gazillion times to try to see if maybe I could find a model in which they were shown, but there weren't any.
Any idea/suggestion? Thanks!
It's probably because of the use of String. As far as I know, String is a reserved word in Alloy, but it is not really implemented at this point. Try to remove the String fields or replace them with something else.
On a more general note, Alloy is not so much about modelling real data (ints, bools and strings), but more about modelling structure, i.e. relationships between entities. For the analysis of structure, you usually don't need concrete data types.
The purpose of building an Alloy model is to capture the essence of a design or system and explore subtle properties. You don't want to include all the details you'd find in a database schema. Your model has lots of implementation details too, such as the ids (which aren't needed since they're implicit in the object identities), and the use of strings instead of conceptual types -- destination, eg, should have a type such as "Location".
So I'd recommend that you start again, and think first about what kinds of questions you'd like this model to answer.
Thanks to everyone, removing strings solved the problem.
However, my "distorted" vision about Alloy's purpose was due to the fact that we were asked to use it but we weren't given a real explanation on how to use it, in most examples all details were written. I guess I'll have to try and study it a bit more!

Resources