Skip to content

TST Providing unit test to snippet GH32414 #43136

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions pandas/tests/test_categorical.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import pandas as pd
import unittest

def series_fill(cat, ele):
if cat.dtype == 'object':
raise TypeError("Given DataFrame is not of category datatype. Please change it to category datatype.")
if ele not in cat.categories:
raise TypeError("Element not present in categories. Cannot be filled in series.")
ser = pd.Series(cat).fillna(ele)
filled = cat.fillna(ser)
return filled

class Test_series_fill(unittest.TestCase):

def test_series_fill(self):
self.assertCountEqual(series_fill(pd.Categorical(["A", "B", None]), "B"), ["A", "B", "B"])
self.assertCountEqual(series_fill(pd.Categorical(["1", "2", "3", None]), "2"), ["1", "2", "3", "2"])

def test_input_value(self):
self.assertRaises(TypeError, series_fill, True)

unittest.main(argv=[''],verbosity=2, exit=False)