Display a variable makes it to be constant ? Rasters.jl bug?

I got something really odd working with Raster 0.8, Julia 1.9:

This is ok:

julia> using Rasters
julia> X = 2
2
julia> X
2
julia> typeof(X)
Int64

but (new session):

julia> using Rasters
julia> X
X
julia> X = 2
ERROR: cannot assign a value to imported variable Dimensions.X from module Main
Stacktrace:
[1] top-level scope
@ REPL[3]:1

By the only fact that I do show a variable (that I don’t know where it is coming), I can’t use it any more to rebind it to some other object ?? Rasters.jl bug ?

Rasters exports the type X.

If you dont want that to happen, use import Rasters instead

1 Like

I think X is a too general-use variable name to be exported by a module (my opinion)

1 Like

But you only have the problem because you used X before defining it? Why are you doing that if you dont want to use it at all?

If you define your variable first it will work.

yes, I understood it and indeed it is the workaround I am using, but I think that it is more a workaround. I didn’t expect the X variable to be exported by a module, I just find it odd and that it is something that would surprise new users, but maybe it is just me… by defining it first it works…

1 Like

I agree it may suprise some people at the start, but also its something you learn quite quickly with the julia REPL.

Working with spatial data X and Y dimensions are used constantly, thecrrason theurecexported. There is a case for not using these types any more as you can actually useckeywords in most places:

raster[X=2] 

But there are a bunch of things dimendion type wrappers make easier, like constructing tuples of indices programatically or passing wrapped data into base methods with dims keywords.