Skip to content
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

TST: add tests for keeping dtype in Series.update #23604

Merged
merged 19 commits into from
Nov 20, 2018
Merged
Changes from 8 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
37 changes: 33 additions & 4 deletions pandas/tests/series/test_combine_concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
import pandas as pd
from pandas import DataFrame, DatetimeIndex, Series, compat, date_range
import pandas.util.testing as tm
from pandas.util.testing import assert_series_equal
from pandas.util.testing import assert_frame_equal, assert_series_equal


class TestSeriesCombine():
class TestSeriesCombine(object):

def test_append(self, datetime_series, string_series, object_series):
appendedSeries = string_series.append(object_series)
Expand Down Expand Up @@ -116,8 +116,37 @@ def test_update(self):
df = DataFrame([{"a": 1}, {"a": 3, "b": 2}])
df['c'] = np.nan

# this will fail as long as series is a sub-class of ndarray
# df['c'].update(Series(['foo'],index=[0])) #####
gfyoung marked this conversation as resolved.
Show resolved Hide resolved
df['c'].update(Series(['foo'], index=[0]))
expected = DataFrame([[1, np.nan, 'foo'], [3, 2., np.nan]],
columns=['a', 'b', 'c'])
assert_frame_equal(df, expected)

def test_update_dtypes(self):
s = Series([1., 2., False, True])
gfyoung marked this conversation as resolved.
Show resolved Hide resolved
other = Series([45], index=[0])
gfyoung marked this conversation as resolved.
Show resolved Hide resolved
s.update(other)

expected = Series([45., 2., False, True])
assert_series_equal(s, expected)

t_src = Series([10, 11, 12])
t = t_src.copy()
other = Series([61, 63], index=[1, 3])
t.update(other)

expected = Series([10, 61, 12])
assert_series_equal(t, expected)

# we always try to keep original dtype, even if other has different one
t = t_src.copy()
t.update(other.astype(float))
assert_series_equal(t, expected)

# if keeping the dtype is not possible, we allow upcasting
t = t_src.copy()
t.update(other + 0.1)
expected = Series([10., 61.1, 12.])
assert_series_equal(t, expected)

def test_concat_empty_series_dtypes_roundtrips(self):

Expand Down