Add nrows to read json.
State: closed

- [x] closes #33916
- [x] tests added / passed
- [x] passes `black pandas`
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`

Add the nrows to read_json parameter that returns only the required number of json from the line delimited json 

Labels:
name: Performance
description: Memory or execution speed performance
name: IO JSON
description: read_json, to_json, json_normalize

Comments:
Hey @jreback 
I have made all the change
As for typing args I tried for All of them but looks like I don't know much, so added as much as possible including nrows that were made necessary. Will try raising a new PR which will add typing hint for all args later.
I hope everything's in order 
It is ready to be reviewed 
Regards.
Can you remove the print statements and repush? CI failure should be unrelated
> Can you remove the print statements and repush? CI failure should be unrelated

Done @WillAyd 
can you show the actual asv results on github (not a link), just dump the text output.
https://github.com/pandas-dev/pandas/runs/722921697
You will find it around 24.68% 
@jreback 
Apologies I actually read your statement wrong. I read the complete opposite hence had shared the link to github runs.
I realized it now so I am sharing the dumps paste

[link to the paste of dumps](https://pastebin.com/E22PAxKe)



Hey @jreback 

Hope you are having a great day

So this PR is basically for the addition of the feature of selecting the number of rows to be returned when the lines parameter is set.

According to the benchmarks I believe that feature is working fine. 

So is it possible that we merge this feature and then create a new issue for the concerns that we are having with the chunk size feature? I have got a grip on this section of the codebase so I should be able to do that too but I believe we should have separate PR's for them.

Thanks and Regards

@hasnain2808 yep that sounds fine. please add a whatsnew (about the nrows feature) and create an issue about chunksize  & perf which can certainly be a followup.

ping on green (for the added whatsnew), put in other enhancements in 1.1
Hey @jreback 
Added the whatsnew and it's green
I hope everything's in order to merge.
Thanks.
@hasnain2808 looks like another merge conflict - can you fix up?

So the benchmarks did show an improvement right? Not entirely clear from the link that you sent; usually at the end of the run you should get something saying PERFORMANCE IMPROVED .  I might be overlooking that from what you shared

As long as that shows an improvement this lgtm
@WillAyd 

Hope you're having a nice day

I will fix the merge conflicts

Yes the memory consumption and time required is low when we use the nrows parameter.

As the nrows parameter is optional, we added a new benchmark for this parameter hence,  the benchmark results do not show the PERFORMANCE IMPROVED verdict.

Pasted the results into the spreadsheet to compare easily
[Link](https://docs.google.com/spreadsheets/d/1MjE2iMrlYnWbnfSyizfYI3IbwSK1z760VKeoYfCBeJs/edit?usp=drivesdk)

Raw dumps are here
https://pastebin.com/E22PAxKe


Please do tell me if there is something else that's needed to be done

Fixed the merge conflicts.
I hope we merge this before some one else adds a what's new into master 
I do not think this failure is related
It started coming once I merged master into my branch to resolve merge conflicts

The benchmark is failing around  0.64% 
```
##[error][  0.65%] ··· arithmetic.ApplyIndex.time_apply_index                 3/10 failed
[  0.65%] ··· =================================== ==========
                             offset                         
              ----------------------------------- ----------
                      <YearEnd: month=12>          1.55±0ms 
                      <YearBegin: month=1>         1.37±0ms 
                 <QuarterEnd: startingMonth=3>     1.71±0ms 
                <QuarterBegin: startingMonth=3>    1.59±0ms 
                           <MonthEnd>              2.25±0ms 
                          <MonthBegin>             1.34±0ms 
                 <DateOffset: days=2, months=2>    3.16±0ms 
                         <BusinessDay>              failed  
                <SemiMonthEnd: day_of_month=15>     failed  
               <SemiMonthBegin: day_of_month=15>    failed  
              =================================== ==========

[  0.65%] ···· For parameters: <BusinessDay>
               Traceback (most recent call last):
                 File "/home/runner/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/asv/benchmark.py", line 1184, in main_run_server
                   main_run(run_args)
                 File "/home/runner/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/asv/benchmark.py", line 1058, in main_run
                   result = benchmark.do_run()
                 File "/home/runner/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/asv/benchmark.py", line 537, in do_run
                   return self.run(*self._current_params)
                 File "/home/runner/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/asv/benchmark.py", line 627, in run
                   samples, number = self.benchmark_timing(timer, min_repeat, max_repeat,
                 File "/home/runner/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/asv/benchmark.py", line 694, in benchmark_timing
                   timing = timer.timeit(number)
                 File "/home/runner/miniconda3/envs/pandas-dev/lib/python3.8/timeit.py", line 177, in timeit
                   timing = self.inner(it, self.timer)
                 File "<timeit-src>", line 6, in inner
                 File "/home/runner/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/asv/benchmark.py", line 599, in <lambda>
                   func = lambda: self.func(*param)
                 File "/home/runner/work/pandas/pandas/asv_bench/benchmarks/arithmetic.py", line 469, in time_apply_index
                   offset.apply_index(self.rng)
                 File "pandas/_libs/tslibs/offsets.pyx", line 87, in pandas._libs.tslibs.offsets.apply_index_wraps.wrapper
                 File "pandas/_libs/tslibs/offsets.pyx", line 1397, in pandas._libs.tslibs.offsets.BusinessDay.apply_index
               AttributeError: 'PeriodIndex' object has no attribute '_addsub_int_array'
               
               For parameters: <SemiMonthEnd: day_of_month=15>
               Traceback (most recent call last):
                 File "/home/runner/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/asv/benchmark.py", line 1184, in main_run_server
                   main_run(run_args)
                 File "/home/runner/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/asv/benchmark.py", line 1058, in main_run
                   result = benchmark.do_run()
                 File "/home/runner/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/asv/benchmark.py", line 537, in do_run
                   return self.run(*self._current_params)
                 File "/home/runner/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/asv/benchmark.py", line 627, in run
                   samples, number = self.benchmark_timing(timer, min_repeat, max_repeat,
                 File "/home/runner/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/asv/benchmark.py", line 694, in benchmark_timing
                   timing = timer.timeit(number)
                 File "/home/runner/miniconda3/envs/pandas-dev/lib/python3.8/timeit.py", line 177, in timeit
                   timing = self.inner(it, self.timer)
                 File "<timeit-src>", line 6, in inner
                 File "/home/runner/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/asv/benchmark.py", line 599, in <lambda>
                   func = lambda: self.func(*param)
                 File "/home/runner/work/pandas/pandas/asv_bench/benchmarks/arithmetic.py", line 469, in time_apply_index
                   offset.apply_index(self.rng)
                 File "pandas/_libs/tslibs/offsets.pyx", line 87, in pandas._libs.tslibs.offsets.apply_index_wraps.wrapper
                 File "pandas/_libs/tslibs/offsets.pyx", line 2319, in pandas._libs.tslibs.offsets.SemiMonthOffset.apply_index
               AttributeError: 'PeriodIndex' object has no attribute '_addsub_int_array'
               
               For parameters: <SemiMonthBegin: day_of_month=15>
               Traceback (most recent call last):
                 File "/home/runner/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/asv/benchmark.py", line 1184, in main_run_server
                   main_run(run_args)
                 File "/home/runner/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/asv/benchmark.py", line 1058, in main_run
                   result = benchmark.do_run()
                 File "/home/runner/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/asv/benchmark.py", line 537, in do_run
                   return self.run(*self._current_params)
                 File "/home/runner/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/asv/benchmark.py", line 627, in run
                   samples, number = self.benchmark_timing(timer, min_repeat, max_repeat,
                 File "/home/runner/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/asv/benchmark.py", line 694, in benchmark_timing
                   timing = timer.timeit(number)
                 File "/home/runner/miniconda3/envs/pandas-dev/lib/python3.8/timeit.py", line 177, in timeit
                   timing = self.inner(it, self.timer)
                 File "<timeit-src>", line 6, in inner
                 File "/home/runner/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/asv/benchmark.py", line 599, in <lambda>
                   func = lambda: self.func(*param)
                 File "/home/runner/work/pandas/pandas/asv_bench/benchmarks/arithmetic.py", line 469, in time_apply_index
                   offset.apply_index(self.rng)
                 File "pandas/_libs/tslibs/offsets.pyx", line 87, in pandas._libs.tslibs.offsets.apply_index_wraps.wrapper
                 File "pandas/_libs/tslibs/offsets.pyx", line 2319, in pandas._libs.tslibs.offsets.SemiMonthOffset.apply_index
               AttributeError: 'PeriodIndex' object has no attribute '_addsub_int_array'

```

ping
Ping
@jreback it's all green.
thanks @hasnain2808 
Thanks @jreback