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

Missing Missing methods for angle, hypot and 2-arg atan #32224

Open
yha opened this issue Jun 3, 2019 · 10 comments
Open

Missing Missing methods for angle, hypot and 2-arg atan #32224

yha opened this issue Jun 3, 2019 · 10 comments
Labels
maths Mathematical functions missing data Base.missing and related functionality

Comments

@yha
Copy link
Contributor

yha commented Jun 3, 2019

Should be fixed with

Base.atan(::Union{Real,Missing}, ::Union{Real,Missing}) = missing
Base.hypot(::Union{Number,Missing}...) = missing
Base.angle(::Missing) = missing

I would open a PR if I could get Julia to build on my Windows machine...

@yha yha changed the title Missing Missing methods for hypot and 2-arg atan Missing Missing methods for angle, hypot and 2-arg atan Jun 3, 2019
@musm
Copy link
Contributor

musm commented Jun 3, 2019

I would open a PR if I could get Julia to build on my Windows machine...

https://github.com/JuliaLang/julia/blob/master/doc/build/windows.md#cygwin-to-mingw-cross-compiling

the packages can be easily installed

make,python2,libiconv,curl,time,p7zip,ccache,mingw64-x86_64-gcc-g++,mingw64-x86_64-gcc-fortran

@JeffBezanson
Copy link
Sponsor Member

I'm curious --- did you actually encounter a need for these or do you just think they should be defined for general reasons?

@JeffBezanson JeffBezanson added the missing data Base.missing and related functionality label Jun 4, 2019
@yha
Copy link
Contributor Author

yha commented Jun 4, 2019

@musm Trying to build, I get
Generating precompile statements...ERROR: LoadError: IOError: stream is closed or unusable
make cleanall doesn't help.

@JeffBezanson I did encounter a need: I was calculating speed (hypot) and heading (atan) from vectors of coordinates which include missings, and was using angle in the calculation of circular means of angles (circmean(x) = angle(mean(exp.(x.*im))))

@ararslan ararslan added the maths Mathematical functions label Jun 6, 2019
@musm
Copy link
Contributor

musm commented Jun 7, 2019

@yha usually that error is fixed by rerunning make

@nalimilan
Copy link
Member

You could try making a PR directly from GitHub. In general I wouldn't recommend that, but in this case it's quite simple (just add the function names to the existing loops in base/missing.jl and test/missing.jl), so it should be doable.

@deszoeke
Copy link

deszoeke commented Apr 21, 2021

All math functions need methods for missing or people will fall back on reliable IEEE NaN practices.
A broadcasting cosd.( ) calls Base.deg2rad, which doesn't handle missing.

Using Revise and adding the method
Base.deg2rad(::Missing) = missing
inside my module results in a seg fault and hang.

It's a doozy of a seg fault. My other shell has lost its user ID, and I can't ssh from a new window anymore. Needless to say, I haven't been able to do intensive testing.

Julia 1.5.3 nalimilan Copr port on CentOS.

@KristofferC
Copy link
Sponsor Member

All math functions need methods for missing or people will fall back on reliable IEEE NaN practices.

It is hard to define "math functions" and people have also claimed that every "string function" should also have an extra method for Missing.

Instead, you can use explicit tools like skipmissing or coalesce. Then you compose missing handling and normal functions instead of having a design where you need to "color" certain functions to have this extra Missing method.

@deszoeke
Copy link

deszoeke commented Apr 21, 2021

In this case, the error is that the basic safe behavior, that an operation (multiplying by pi/180) on a missing returns missing, did not accept the missing type.

Since my data are Floats, I will use a cringeworthy function to preemptively convert all missing to NaN.

@pdeffebach
Copy link
Contributor

pdeffebach commented Apr 26, 2021

OP if you aren't aware of passmissing in Missings.jl that will fix your problem.

Find the highest-level function that accepts a scalar and wrap it in passmissing. Then it will propagate missings for you. No need for NaN.

@deszoeke
Copy link

Thanks. I was not aware of ‘passmissing’, but will find it useful.

The type error here was actually from trying to broadcast on an array defined in the lexical scope of the function, rather than an argument passed into the function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maths Mathematical functions missing data Base.missing and related functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants