-
-
Notifications
You must be signed in to change notification settings - Fork 17.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
REF/TST: collect astype tests (#37282)
- Loading branch information
1 parent
4a08c02
commit 6ac3765
Showing
5 changed files
with
339 additions
and
318 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import numpy as np | ||
import pytest | ||
|
||
import pandas as pd | ||
import pandas._testing as tm | ||
|
||
|
||
class TestConvertDtypes: | ||
@pytest.mark.parametrize( | ||
"convert_integer, expected", [(False, np.dtype("int32")), (True, "Int32")] | ||
) | ||
def test_convert_dtypes(self, convert_integer, expected): | ||
# Specific types are tested in tests/series/test_dtypes.py | ||
# Just check that it works for DataFrame here | ||
df = pd.DataFrame( | ||
{ | ||
"a": pd.Series([1, 2, 3], dtype=np.dtype("int32")), | ||
"b": pd.Series(["x", "y", "z"], dtype=np.dtype("O")), | ||
} | ||
) | ||
result = df.convert_dtypes(True, True, convert_integer, False) | ||
expected = pd.DataFrame( | ||
{ | ||
"a": pd.Series([1, 2, 3], dtype=expected), | ||
"b": pd.Series(["x", "y", "z"], dtype="string"), | ||
} | ||
) | ||
tm.assert_frame_equal(result, expected) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import numpy as np | ||
|
||
from pandas import Series | ||
import pandas._testing as tm | ||
|
||
|
||
class TestInferObjects: | ||
def test_infer_objects_series(self): | ||
# GH#11221 | ||
actual = Series(np.array([1, 2, 3], dtype="O")).infer_objects() | ||
expected = Series([1, 2, 3]) | ||
tm.assert_series_equal(actual, expected) | ||
|
||
actual = Series(np.array([1, 2, 3, None], dtype="O")).infer_objects() | ||
expected = Series([1.0, 2.0, 3.0, np.nan]) | ||
tm.assert_series_equal(actual, expected) | ||
|
||
# only soft conversions, unconvertable pass thru unchanged | ||
actual = Series(np.array([1, 2, 3, None, "a"], dtype="O")).infer_objects() | ||
expected = Series([1, 2, 3, None, "a"]) | ||
|
||
assert actual.dtype == "object" | ||
tm.assert_series_equal(actual, expected) |
Oops, something went wrong.