EA: fillna should accept same type #32414
State: closed

A unit test has been added to check the validity of pd.Categorical() . This PR is with respect to the GitHub issue no. 32414.
Thanks

- [x] closes #32414

Labels:
name: Testing
description: pandas testing functions or related to the test suite
name: Missing-data
description: np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
name: ExtensionArray
description: Extending pandas with custom dtypes or arrays.
name: Stale

Comments:
Hello @Bhavay192! Thanks for updating this PR. We checked the lines you've touched for [PEP 8](https://www.python.org/dev/peps/pep-0008) issues, and found:

* In the file [`pandas/tests/series/methods/test_fillna.py`](https://github.com/pandas-dev/pandas/blob/12ab6aa4bc12178ba9e7408000f3894e01facdd4/pandas/tests/series/methods/test_fillna.py):

> [Line 683:5](https://github.com/pandas-dev/pandas/blob/12ab6aa4bc12178ba9e7408000f3894e01facdd4/pandas/tests/series/methods/test_fillna.py#L683): [E304](https://duckduckgo.com/?q=pep8%20E304) blank lines found after function decorator



##### Comment last updated at 2021-11-20 10:33:09 UTC
I request all the members to please review my PR and please tell if any changes needs to done. Thanks
hey @phofl , thanks for reviewing. I couldn't understand where my test is failing. It would be really helpful if you could help me understand in a little more detail as I'm quite new to open source. Hope you understand. Also I checked the pandas documentation but couldn't find anything that suits to my test.

I was talking about https://pandas.pydata.org/docs/development/contributing_codebase.html# and your Pep 8 warning.

Is your test passing locally? If yes you can check https://dev.azure.com/pandas-dev/pandas/_build/results?buildId=64906&view=logs&j=404760ec-14d3-5d48-e580-13034792878f&t=f81e4cc8-d61a-5fb8-36be-36768e5c561a&l=59 to get the stacktrace

hey @phofl , thanks for suggesting me the failure. I opened the link in you comments . It is quite difficult to interpret where my test is failing but by seeing the logs, it makes me feel that the code is failing with the TypeError that i have raised. Please cross check my code once and tell me if could you find my mistake. Also i ran the test locally on  my laptop using the unittest module of python, soo there might be some changes with pytest. Please see if you can help me with the error. Thanks
Running them with unittest is not helpful, since we are using a lot of pytest functionality. Please run them with pytest then your test will fail locally too
hey @phofl, thanks for replying. Based on your comment I ran my test locally on my machine with pytest module and I have updated the code with the changes that were causing the error. Hope soo that it shall now pass all the tests and doesn't conflict with the rest of code. Please review the updated code. Thanks
hey @phofl, I have updated the pull request. Please review it once.
Tests are still failing
I'm unable to understand why they are still failing. I made all the necessary changes that you said, made a complete test out of that code snippet and its working fine on my machine and also I tried to design the test in the style of the other tests in that file. Still its failing .
> and its working fine on my machine

Pretty sure the code, as it's written, won't pass - could you show what you ran and what your output is please? Perhaps you have some commits you haven't pushed yet?
hey @MarcoGorelli, thanks for replying. I tried to run only the function I have written on my machine without the class. As i made the class and ran it showed some error and I'm unable to intrepret it.
I will attach the my code and the output here. Please review it.

Code
![Code](https://user-images.githubusercontent.com/56443877/132088626-f3360a3b-31ad-4e0b-a0b3-ef6f34b685cf.PNG)

Output
![Output](https://user-images.githubusercontent.com/56443877/132088635-f3f55c96-25f2-4197-b1ea-ecc135b3f8eb.PNG)

However, If I try to run test_fillna.py complete file on my machine, It passes all the 39 tests, but fails on only 1 test. I'm adding below the output of that too.
![Output](https://user-images.githubusercontent.com/56443877/132088709-6fa565ce-b7de-4dcf-9506-34e183dfd10a.PNG)

Try running `pytest pandas/tests/series/methods/test_fillna.py -k test_series_fill`, that'll reproduce the error you see in CI

(you may need to replace `/` with `\` if you're on Windows)
Hey @MarcoGorelli, I tested the complete test_fillna.py in my machine, it shows no errors. However, on running the above command that you told, it gives just an import error in a seperate file and not in test_fillna.py. Now, what should i do next?? 
can you paste your command and output please?
Yes, my testing_fillna.py is same as the test_fillna.py and i ran it. it shows the following command
![image](https://user-images.githubusercontent.com/56443877/132101436-b3e18526-fd1c-44cc-9928-233303d6fc00.png)

> However, on running the above command that you told, it gives just an import error in a seperate file and not in test_fillna.py

can you paste command and output of this?
![Output](https://user-images.githubusercontent.com/56443877/132101668-e19f585f-dd03-465b-82f4-cd16386ac81f.PNG)

This pull request is stale because it has been open for thirty days with no activity. Please update or respond to this comment if you're still interested in working on this.
Appears this PR has been dormant for a while and is still failing in the CI so closing. If interested in continuing, please merge master, address related comments and we can reopen.
Hey, I was a bit busy soo couldn't contribute to it. I'm thinking of working on this PR now.

Hey, my function is just working fine I believe. The problem is coming with other functions. I have tested my function by commenting out the error-causing functions and all the tests have passed. Please open the PR, soo that I can discuss on this further. Thanks
sure, reopened
Hey @MarcoGorelli, May I show u my code ?? Cause the problem comes here that the test is failing for other codes in the file. If I run my code alone on a separate file it just works fine. Soo may I?? 
feel free to paste your code (copy and paste it rather than showing a screenshot)
Hey @MarcoGorelli , sorry for late replying. I will surely paste my code sample here so that u can have a look. Please give me some time.
```python
def test_fillna_categorical(self, fill_value, expected_output):
        # GH32414
        data = ["A", "B", np.nan, np.nan, "C"]
        cat = Categorical(data, categories=["A", "B", "C"])
        ser = Series(cat)
        exp_cat = Categorical(expected_output, categories=["A", "B", "C"])
        exp_ser = Series(exp_cat)
        result_ser = ser.fillna(fill_value)
        filled = cat.fillna(fill_value)
        tm.assert_almost_equal(result_ser, exp_ser)
        tm.assert_almost_equal(filled, exp_cat)
```
@MarcoGorelli , this is my code sample. Please review it soo that I can merge it. Thanks
Please show your whole file - I don't believe that that one passes because `self` would be undefined.
Please also show what you ran, and the output