-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TST/REF: collect tests by method from generic #37421
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 all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5a3289e
TST/REF: method specific test file for pipe
jbrockmendel ef505f4
TST/REF: collect tests by method from tests.generic
jbrockmendel 694e831
TST/REF: test_sample
jbrockmendel c90b051
Merge branch 'master' of https://github.com/pandas-dev/pandas into ts…
jbrockmendel 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,53 @@ | ||
import numpy as np | ||
import pytest | ||
|
||
from pandas.compat.numpy import np_version_under1p17 | ||
|
||
from pandas import DataFrame | ||
import pandas._testing as tm | ||
import pandas.core.common as com | ||
|
||
|
||
class TestSample: | ||
@pytest.mark.parametrize( | ||
"func_str,arg", | ||
[ | ||
("np.array", [2, 3, 1, 0]), | ||
pytest.param( | ||
"np.random.MT19937", | ||
3, | ||
marks=pytest.mark.skipif(np_version_under1p17, reason="NumPy<1.17"), | ||
), | ||
pytest.param( | ||
"np.random.PCG64", | ||
11, | ||
marks=pytest.mark.skipif(np_version_under1p17, reason="NumPy<1.17"), | ||
), | ||
], | ||
) | ||
def test_sample_random_state(self, func_str, arg): | ||
# GH#32503 | ||
df = DataFrame({"col1": range(10, 20), "col2": range(20, 30)}) | ||
result = df.sample(n=3, random_state=eval(func_str)(arg)) | ||
expected = df.sample(n=3, random_state=com.random_state(eval(func_str)(arg))) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
def test_sample_upsampling_without_replacement(self): | ||
# GH#27451 | ||
|
||
df = DataFrame({"A": list("abc")}) | ||
msg = ( | ||
"Replace has to be set to `True` when " | ||
"upsampling the population `frac` > 1." | ||
) | ||
with pytest.raises(ValueError, match=msg): | ||
df.sample(frac=2, replace=False) | ||
|
||
def test_sample_is_copy(self): | ||
# GH#27357, GH#30784: ensure the result of sample is an actual copy and | ||
# doesn't track the parent dataframe / doesn't give SettingWithCopy warnings | ||
df = DataFrame(np.random.randn(10, 3), columns=["a", "b", "c"]) | ||
df2 = df.sample(3) | ||
|
||
with tm.assert_produces_warning(None): | ||
df2["d"] = 1 |
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,38 @@ | ||
import pytest | ||
|
||
from pandas import DataFrame, Series | ||
import pandas._testing as tm | ||
|
||
|
||
class TestPipe: | ||
@pytest.mark.parametrize("klass", [Series, DataFrame]) | ||
def test_pipe(self, klass): | ||
obj = DataFrame({"A": [1, 2, 3]}) | ||
expected = DataFrame({"A": [1, 4, 9]}) | ||
if klass is Series: | ||
obj = obj["A"] | ||
expected = expected["A"] | ||
|
||
f = lambda x, y: x ** y | ||
result = obj.pipe(f, 2) | ||
tm.assert_equal(result, expected) | ||
|
||
@pytest.mark.parametrize("klass", [Series, DataFrame]) | ||
def test_pipe_tuple(self, klass): | ||
obj = DataFrame({"A": [1, 2, 3]}) | ||
if klass is Series: | ||
obj = obj["A"] | ||
|
||
f = lambda x, y: y | ||
result = obj.pipe((f, "y"), 0) | ||
tm.assert_equal(result, obj) | ||
|
||
@pytest.mark.parametrize("klass", [Series, DataFrame]) | ||
def test_pipe_tuple_error(self, klass): | ||
obj = DataFrame({"A": [1, 2, 3]}) | ||
if klass is Series: | ||
obj = obj["A"] | ||
|
||
f = lambda x, y: y | ||
with pytest.raises(ValueError): | ||
obj.pipe((f, "y"), x=1, y=0) |
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 |
---|---|---|
|
@@ -3,14 +3,11 @@ | |
import numpy as np | ||
import pytest | ||
|
||
from pandas.compat.numpy import np_version_under1p17 | ||
|
||
from pandas.core.dtypes.common import is_scalar | ||
|
||
import pandas as pd | ||
from pandas import DataFrame, Series, date_range | ||
import pandas._testing as tm | ||
import pandas.core.common as com | ||
|
||
# ---------------------------------------------------------------------- | ||
# Generic types test cases | ||
|
@@ -404,26 +401,6 @@ def test_sample(self): | |
weights_with_None[5] = 0.5 | ||
self._compare(o.sample(n=1, axis=0, weights=weights_with_None), o.iloc[5:6]) | ||
|
||
def test_sample_upsampling_without_replacement(self): | ||
# GH27451 | ||
|
||
df = DataFrame({"A": list("abc")}) | ||
msg = ( | ||
"Replace has to be set to `True` when " | ||
"upsampling the population `frac` > 1." | ||
) | ||
with pytest.raises(ValueError, match=msg): | ||
df.sample(frac=2, replace=False) | ||
|
||
def test_sample_is_copy(self): | ||
# GH-27357, GH-30784: ensure the result of sample is an actual copy and | ||
# doesn't track the parent dataframe / doesn't give SettingWithCopy warnings | ||
df = DataFrame(np.random.randn(10, 3), columns=["a", "b", "c"]) | ||
df2 = df.sample(3) | ||
|
||
with tm.assert_produces_warning(None): | ||
df2["d"] = 1 | ||
|
||
def test_size_compat(self): | ||
# GH8846 | ||
# size property should be defined | ||
|
@@ -534,7 +511,7 @@ def test_pct_change(self, periods, fill_method, limit, exp): | |
class TestNDFrame: | ||
# tests that don't fit elsewhere | ||
|
||
def test_sample(sel): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wow, wonder how this worked |
||
def test_sample(self): | ||
# Fixes issue: 2419 | ||
# additional specific object based tests | ||
|
||
|
@@ -645,29 +622,6 @@ def test_sample(sel): | |
with pytest.raises(ValueError): | ||
df.sample(1, weights=s4) | ||
|
||
@pytest.mark.parametrize( | ||
"func_str,arg", | ||
[ | ||
("np.array", [2, 3, 1, 0]), | ||
pytest.param( | ||
"np.random.MT19937", | ||
3, | ||
marks=pytest.mark.skipif(np_version_under1p17, reason="NumPy<1.17"), | ||
), | ||
pytest.param( | ||
"np.random.PCG64", | ||
11, | ||
marks=pytest.mark.skipif(np_version_under1p17, reason="NumPy<1.17"), | ||
), | ||
], | ||
) | ||
def test_sample_random_state(self, func_str, arg): | ||
# GH32503 | ||
df = DataFrame({"col1": range(10, 20), "col2": range(20, 30)}) | ||
result = df.sample(n=3, random_state=eval(func_str)(arg)) | ||
expected = df.sample(n=3, random_state=com.random_state(eval(func_str)(arg))) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
def test_squeeze(self): | ||
# noop | ||
for s in [tm.makeFloatSeries(), tm.makeStringSeries(), tm.makeObjectSeries()]: | ||
|
@@ -837,34 +791,6 @@ def test_equals(self): | |
df2 = df1.set_index(["floats"], append=True) | ||
assert df3.equals(df2) | ||
|
||
def test_pipe(self): | ||
df = DataFrame({"A": [1, 2, 3]}) | ||
f = lambda x, y: x ** y | ||
result = df.pipe(f, 2) | ||
expected = DataFrame({"A": [1, 4, 9]}) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
result = df.A.pipe(f, 2) | ||
tm.assert_series_equal(result, expected.A) | ||
|
||
def test_pipe_tuple(self): | ||
df = DataFrame({"A": [1, 2, 3]}) | ||
f = lambda x, y: y | ||
result = df.pipe((f, "y"), 0) | ||
tm.assert_frame_equal(result, df) | ||
|
||
result = df.A.pipe((f, "y"), 0) | ||
tm.assert_series_equal(result, df.A) | ||
|
||
def test_pipe_tuple_error(self): | ||
df = DataFrame({"A": [1, 2, 3]}) | ||
f = lambda x, y: y | ||
with pytest.raises(ValueError): | ||
df.pipe((f, "y"), x=1, y=0) | ||
|
||
with pytest.raises(ValueError): | ||
df.A.pipe((f, "y"), x=1, y=0) | ||
|
||
@pytest.mark.parametrize("box", [pd.Series, pd.DataFrame]) | ||
def test_axis_classmethods(self, box): | ||
obj = box(dtype=object) | ||
|
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
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.
hmm thought we had a specific module for metadata tests
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.
@TomAugspurger is there a better home for these?
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.
Sorry for the delay. We have some in
pandas/tests/generic/test_finalize.py
.