MCPcopy Create free account
hub / github.com/dask/dask / test_combine

Function test_combine

dask/dataframe/tests/test_dataframe.py:1805–1847  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1803
1804
1805def test_combine():
1806 df1 = pd.DataFrame(
1807 {
1808 "A": np.random.choice([1, 2, np.nan], 100),
1809 "B": np.random.choice(["a", "b", "nan"], 100),
1810 }
1811 )
1812
1813 df2 = pd.DataFrame(
1814 {
1815 "A": np.random.choice([1, 2, 3], 100),
1816 "B": np.random.choice(["a", "b", "c"], 100),
1817 }
1818 )
1819 ddf1 = dd.from_pandas(df1, 4)
1820 ddf2 = dd.from_pandas(df2, 5)
1821
1822 first = lambda a, b: a
1823
1824 # You can add series with strings and nans but you can't add scalars 'a' + np.nan
1825 str_add = lambda a, b: a + b if a is not np.nan else a
1826
1827 # DataFrame
1828 for dda, ddb, a, b, runs in [
1829 (ddf1, ddf2, df1, df2, [(add, None), (first, None)]),
1830 (ddf1.A, ddf2.A, df1.A, df2.A, [(add, None), (add, 100), (first, None)]),
1831 (
1832 ddf1.B,
1833 ddf2.B,
1834 df1.B,
1835 df2.B,
1836 [(str_add, None), (str_add, "d"), (first, None)],
1837 ),
1838 ]:
1839 for func, fill_value in runs:
1840 sol = a.combine(b, func, fill_value=fill_value)
1841 assert_eq(dda.combine(ddb, func, fill_value=fill_value), sol)
1842 assert_eq(dda.combine(b, func, fill_value=fill_value), sol)
1843
1844 assert_eq(
1845 ddf1.combine(ddf2, add, overwrite=False), df1.combine(df2, add, overwrite=False)
1846 )
1847 assert dda.combine(ddb, add)._name == dda.combine(ddb, add)._name
1848
1849
1850def test_combine_first():

Callers

nothing calls this directly

Calls 4

combineMethod · 0.95
assert_eqFunction · 0.90
choiceMethod · 0.45
combineMethod · 0.45

Tested by

no test coverage detected