Skip to content

Split and parametrize test_operators #19173

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 16 commits into from
Jan 15, 2018
Merged
Show file tree
Hide file tree
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
47 changes: 47 additions & 0 deletions pandas/tests/frame/test_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,53 @@
_check_mixed_int)


class TestDataFrameArithmetic(object):

@pytest.mark.xfail(reason='GH#7996 datetime64 units not converted to nano')
def test_frame_sub_datetime64_not_ns(self):
df = pd.DataFrame(date_range('20130101', periods=3))
dt64 = np.datetime64('2013-01-01')
assert dt64.dtype == 'datetime64[D]'
res = df - dt64
expected = pd.DataFrame([pd.Timedelta(days=0), pd.Timedelta(days=1),
pd.Timedelta(days=2)])
tm.assert_frame_equal(res, expected)

@pytest.mark.parametrize('data', [
[1, 2, 3],
[1.1, 2.2, 3.3],
[pd.Timestamp('2011-01-01'), pd.Timestamp('2011-01-02'), pd.NaT],
['x', 'y', 1]])
@pytest.mark.parametrize('dtype', [None, object])
def test_frame_radd_str_invalid(self, dtype, data):
df = DataFrame(data, dtype=dtype)
with pytest.raises(TypeError):
'foo_' + df

@pytest.mark.parametrize('dtype', [None, object])
def test_frame_with_dtype_radd_int(self, dtype):
df = pd.DataFrame([1, 2, 3], dtype=dtype)
expected = pd.DataFrame([2, 3, 4], dtype=dtype)
result = 1 + df
assert_frame_equal(result, expected)
result = df + 1
assert_frame_equal(result, expected)

@pytest.mark.parametrize('dtype', [None, object])
def test_frame_with_dtype_radd_nan(self, dtype):
df = pd.DataFrame([1, 2, 3], dtype=dtype)
expected = pd.DataFrame([np.nan, np.nan, np.nan], dtype=dtype)
result = np.nan + df
assert_frame_equal(result, expected)
result = df + np.nan
assert_frame_equal(result, expected)

def test_frame_radd_str(self):
df = pd.DataFrame(['x', np.nan, 'x'])
assert_frame_equal('a' + df, pd.DataFrame(['ax', np.nan, 'ax']))
assert_frame_equal(df + 'a', pd.DataFrame(['xa', np.nan, 'xa']))


class TestDataFrameOperators(TestData):

def test_operators(self):
Expand Down
14 changes: 13 additions & 1 deletion pandas/tests/series/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pytest

from datetime import datetime
from datetime import datetime, timedelta

import sys
import string
Expand All @@ -29,6 +29,18 @@

class TestSeriesDtypes(TestData):

def test_dt64_series_astype_object(self):
dt64ser = Series(date_range('20130101', periods=3))
result = dt64ser.astype(object)
assert isinstance(result.iloc[0], datetime)
assert result.dtype == np.object_

def test_td64_series_astype_object(self):
tdser = Series(['59 Days', '59 Days', 'NaT'], dtype='timedelta64[ns]')
result = tdser.astype(object)
assert isinstance(result.iloc[0], timedelta)
assert result.dtype == np.object_

@pytest.mark.parametrize("dtype", ["float32", "float64",
"int64", "int32"])
def test_astype(self, dtype):
Expand Down
Loading