Skip to content

scalar inputs yield ndim=0 array outputs #646

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

Open
wholmgren opened this issue Jan 19, 2019 · 4 comments
Open

scalar inputs yield ndim=0 array outputs #646

wholmgren opened this issue Jan 19, 2019 · 4 comments
Milestone

Comments

@wholmgren
Copy link
Member

Describe the bug
pvlib has a policy that the output type should be as similar as possible to the input type. So, for all scalar input, most functions should return a scalar output. However, some functions return ndim=0 array outputs instead of true scalars. I know this happens with irradiance.perez, but I think it happens with a handful of functions.

To Reproduce

    out = irradiance.perez(40, 180, 118.45831879, 939.95469881,
                           1321.1655834833093, 10.56413562, 144.76567754,
                           1.01688136)
    assert np.isscalar(out)

Expected behavior
The function should return a scalar, not an ndim=0 array.

Versions:

  • pvlib.__version__: 0.6.0
  • pandas.__version__: many
  • numpy.__version__: many
  • python: many

Additional context
We've previously discussed creating utility functions and decorators to handle type issues like this one. See #635 for example.

The first thing we need to do is catalog which functions exhibit this behavior.

@wholmgren wholmgren added this to the 0.7.0 milestone Jan 19, 2019
@wholmgren wholmgren mentioned this issue Jan 19, 2019
8 tasks
@markcampanelli
Copy link
Contributor

This is a bit of a PITA: numpy/numpy#12636

@mikofski
Copy link
Member

mikofski commented Jan 19, 2019

I recently got bit by this too in scipy

@markcampanelli
Copy link
Contributor

@mikofski Thanks for pushing on that vectorized newton in scipy, it has been quite useful. I am a bit concerned about the different output formats in the scalar vs. vectorized cases, however. Seems like that leads to the same issue we are discussing here.

@wholmgren
Copy link
Member Author

Thanks @markcampanelli for raising the issue with numpy and bringing it to my attention here. I'm less convinced that we should put much effort into it within pvlib.

@wholmgren wholmgren modified the milestones: 0.7.0, 0.8.0 Nov 26, 2019
@wholmgren wholmgren modified the milestones: 0.8.0, Someday Aug 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants