-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TST: moved file test_concat.py to folder ./concat/ (#37243) #37360
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4cfa5a0
TST: moved file test_concat.py to folder ./concat/ (#37243)
kamilt5 bf3030d
splitted class TestAppendCommon to file test_append_common.py
kamilt5 1b96b30
splitted class TestAppend to file test_append.py
kamilt5 7b7d0a9
split class TestAppend to file test_append.py
kamilt5 50d4254
split class TestDataFrameConcat to file test_dataframe.py
kamilt5 b78767e
pre-commit fixes
kamilt5 7f126e4
Merge branch 'master' into i37243_move_files
kamilt5 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,125 @@ | ||
import numpy as np | ||
import pytest | ||
|
||
import pandas as pd | ||
from pandas import ( | ||
Series, | ||
) | ||
|
||
|
||
class TestSeriesConcat: | ||
@pytest.mark.parametrize( | ||
"dtype", ["float64", "int8", "uint8", "bool", "m8[ns]", "M8[ns]"] | ||
) | ||
def test_concat_empty_series_dtypes_match_roundtrips(self, dtype): | ||
dtype = np.dtype(dtype) | ||
|
||
result = pd.concat([Series(dtype=dtype)]) | ||
assert result.dtype == dtype | ||
|
||
result = pd.concat([Series(dtype=dtype), Series(dtype=dtype)]) | ||
assert result.dtype == dtype | ||
|
||
def test_concat_empty_series_dtypes_roundtrips(self): | ||
|
||
# round-tripping with self & like self | ||
dtypes = map(np.dtype, ["float64", "int8", "uint8", "bool", "m8[ns]", "M8[ns]"]) | ||
|
||
def int_result_type(dtype, dtype2): | ||
typs = {dtype.kind, dtype2.kind} | ||
if not len(typs - {"i", "u", "b"}) and ( | ||
dtype.kind == "i" or dtype2.kind == "i" | ||
): | ||
return "i" | ||
elif not len(typs - {"u", "b"}) and ( | ||
dtype.kind == "u" or dtype2.kind == "u" | ||
): | ||
return "u" | ||
return None | ||
|
||
def float_result_type(dtype, dtype2): | ||
typs = {dtype.kind, dtype2.kind} | ||
if not len(typs - {"f", "i", "u"}) and ( | ||
dtype.kind == "f" or dtype2.kind == "f" | ||
): | ||
return "f" | ||
return None | ||
|
||
def get_result_type(dtype, dtype2): | ||
result = float_result_type(dtype, dtype2) | ||
if result is not None: | ||
return result | ||
result = int_result_type(dtype, dtype2) | ||
if result is not None: | ||
return result | ||
return "O" | ||
|
||
for dtype in dtypes: | ||
for dtype2 in dtypes: | ||
if dtype == dtype2: | ||
continue | ||
|
||
expected = get_result_type(dtype, dtype2) | ||
result = pd.concat([Series(dtype=dtype), Series(dtype=dtype2)]).dtype | ||
assert result.kind == expected | ||
|
||
@pytest.mark.parametrize( | ||
"left,right,expected", | ||
[ | ||
# booleans | ||
(np.bool_, np.int32, np.int32), | ||
(np.bool_, np.float32, np.object_), | ||
# datetime-like | ||
("m8[ns]", np.bool_, np.object_), | ||
("m8[ns]", np.int64, np.object_), | ||
("M8[ns]", np.bool_, np.object_), | ||
("M8[ns]", np.int64, np.object_), | ||
# categorical | ||
("category", "category", "category"), | ||
("category", "object", "object"), | ||
], | ||
) | ||
def test_concat_empty_series_dtypes(self, left, right, expected): | ||
result = pd.concat([Series(dtype=left), Series(dtype=right)]) | ||
assert result.dtype == expected | ||
|
||
def test_concat_empty_series_dtypes_triple(self): | ||
|
||
assert ( | ||
pd.concat( | ||
[Series(dtype="M8[ns]"), Series(dtype=np.bool_), Series(dtype=np.int64)] | ||
).dtype | ||
== np.object_ | ||
) | ||
|
||
def test_concat_empty_series_dtype_category_with_array(self): | ||
# GH#18515 | ||
assert ( | ||
pd.concat( | ||
[Series(np.array([]), dtype="category"), Series(dtype="float64")] | ||
).dtype | ||
== "float64" | ||
) | ||
|
||
def test_concat_empty_series_dtypes_sparse(self): | ||
result = pd.concat( | ||
[ | ||
Series(dtype="float64").astype("Sparse"), | ||
Series(dtype="float64").astype("Sparse"), | ||
] | ||
) | ||
assert result.dtype == "Sparse[float64]" | ||
|
||
result = pd.concat( | ||
[Series(dtype="float64").astype("Sparse"), Series(dtype="float64")] | ||
) | ||
# TODO: release-note: concat sparse dtype | ||
expected = pd.SparseDtype(np.float64) | ||
assert result.dtype == expected | ||
|
||
result = pd.concat( | ||
[Series(dtype="float64").astype("Sparse"), Series(dtype="object")] | ||
) | ||
# TODO: release-note: concat sparse dtype | ||
expected = pd.SparseDtype("object") | ||
assert result.dtype == expected |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is typo in commit message, it should be "split class TestSeriesConcat to file test_series.py"