Support for PEP 3141 numbers
State: closed

- [x] closes #22903
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry


Labels:
name: Numeric Operations
description: Arithmetic, Comparison, and Logical operations
name: Algos
description: Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff

Comments:
### PROBLEM
calling `pandas.api.types.is_scalar` returns `False` for Fraction or Number
### FIX
calling `numpy.isscalar(val)` within `is_scalar` function

Thanks for the fix @brute4s99 

Can you add a test (a test that fails before the fix, and that passes with it), and a line in the bugs section of the whatsnew file for 0.24 please?
> Thanks for the fix @brute4s99
> 
> Can you add a test (a test that fails before the fix, and that passes with it), and a line in the bugs section of the whatsnew file for 0.24 please?

sure, @datapythonista ! I didn't know about the whatsnew file, so thanks !
no problem, took me several PRs before I started remembering about the whatsnew myself ;)
Simple solution, may well be the best one.  This will definitely need a performance check.
where can I connect with all the devs, @datapythonista ?
do we have any IRC channel or similar?
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/22952?src=pr&el=h1) Report
> Merging [#22952](https://codecov.io/gh/pandas-dev/pandas/pull/22952?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/deb7b4d5003b939f47e525bcdaceeea48622a73a?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/22952/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/22952?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##           master   #22952   +/-   ##
=======================================
  Coverage   92.28%   92.28%           
=======================================
  Files         161      161           
  Lines       51451    51451           
=======================================
  Hits        47483    47483           
  Misses       3968     3968
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.68% <ø> (ø)` | :arrow_up: |
| #single | `42.28% <ø> (ø)` | :arrow_up: |


------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/22952?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/22952?src=pr&el=footer). Last update [deb7b4d...e5f084a](https://codecov.io/gh/pandas-dev/pandas/pull/22952?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

> Simple solution, may well be the best one. This will definitely need a performance check.

I just thought of reusing exisitng code, since we already require `numpy` to install `pandas` :smile: 
@brute4s99 you can use gitter: https://gitter.im/pydata/pandas

If it's related to this PR, is usually better to discuss here, so other people interested/reviewing are aware of the discussions.

In this case the issue is that the file you're modifying is a `pyx` file. Meaning that the syntax is Cython, and it gets converted to C and compiled. And calling a numpy Python function will have an impact on the speed (and we use Cython and compile the file to speed up things). If you're not familiar with Cython and those things, it can be difficult to fix this issue in a more performant way.
> do we have any IRC channel or similar?

There's gitter, though I don't know how much it is used.  The conversation here in GH likely your best bet.

> I just thought of reusing exisitng code, since we already require numpy to install pandas

That's a good intuition, and _may_ end up being the optimal way to go, but in the cython code we make an extra effort to avoid making pure-python calls.  So if there turned out to be a C-implementation, we'd want to use that.  As it is I expect @jreback's suggestion to directly do an isinstance check is the easiest solution.
>  As it is I expect @jreback's suggestion to directly do an isinstance check is the easiest solution.

I was thinking the same, but then dropped it presuming importing Fraction and Number might cause slowness.
> pls add a test

Can you please elaborate, @jreback ?
I am new to contributing.
You need to add a test that shows that your changes all work as expected. 
Somewhere around here:

https://github.com/pandas-dev/pandas/blob/1a12c41d201f56439510e683fadfed1218ea9067/pandas/tests/dtypes/test_inference.py#L1119

Hello @brute4s99! Thanks for updating the PR.

 - There are no PEP8 issues in the file [`pandas/tests/dtypes/test_inference.py`](https://github.com/brute4s99/pandas/blob/35a5b2fc68181f26a5f25d8c0f9688e3eaf5c4a2/pandas/tests/dtypes/test_inference.py) !



##### Comment last updated on October 03, 2018 at 09:54 Hours UTC
> Somewhere around here:
> 
> [pandas/pandas/tests/dtypes/test_inference.py](https://github.com/pandas-dev/pandas/blob/1a12c41d201f56439510e683fadfed1218ea9067/pandas/tests/dtypes/test_inference.py#L1119)
> 
> Line 1119 in [1a12c41](/pandas-dev/pandas/commit/1a12c41d201f56439510e683fadfed1218ea9067)
>  def test_is_scalar_builtin_scalars(self):

Tests have been added and passed ! :smile: 
## please ignore failed Travis CI :  :issue:[`#22934`](https://github.com/pandas-dev/pandas/issues/22934)
this is a random error by Travis CI.
@jreback please review
@jreback please review, I just re-did the changes after a `git fetch upstream`
can you merge master and update
can you merge master
please review, @datapythonista @jreback 
rebase. small change @brute4s99 
is this done right? @jreback 
Check the diff of the PR, something went wrong and it has lots of unrelated changes. Can you fix it please, so we can move forward with it.
okayyy, I jumbled up.
Found my mistake, @datapythonista .
Will repair this ASAP
please review, @datapythonista 
I believe it's done right this time!
I accidentally rebased on origin/master, that was ~350 commits behind upstream/master
steps taken:-
1. reverted HEAD to just before rebase
2. merged `upstream/master` into `origin/is_scalar`
2. updated `origin/master` to get NO diffs in `upstream/master` and `origin/master`
3. ran `git rebase origin/master` and fixed a conflict in `doc/source/whatsnew/v0.24.0.rst`
4. pushed to `origin/is_scalar`.

@datapythonista over to you; merge when satisfied.
Thanks @brute4s99