Skip to content
This repository was archived by the owner on Feb 2, 2024. It is now read-only.

Commit 4301a9a

Browse files
Vyacheslav-Smirnovshssf
authored andcommitted
Series rename new pipeline (#373)
* Init Series.rename method in new pipeline - Add 10 new tests - Rename using non-string types not works * Skip 4 rename tests with int and float types - Required Series name support for full scalar types (not only str)
1 parent cd55e15 commit 4301a9a

4 files changed

Lines changed: 176 additions & 22 deletions

File tree

sdc/datatypes/hpat_pandas_series_functions.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2147,6 +2147,77 @@ def hpat_pandas_series_quantile_impl(self, q=0.5, interpolation='linear'):
21472147
return hpat_pandas_series_quantile_impl
21482148

21492149

2150+
@overload_method(SeriesType, 'rename')
2151+
def hpat_pandas_series_rename(self, index=None, copy=True, inplace=False, level=None):
2152+
"""
2153+
Pandas Series method :meth:`pandas.Series.rename` implementation.
2154+
Alter Series index labels or name.
2155+
.. only:: developer
2156+
Test: python -m sdc.runtests -k sdc.tests.test_series.TestSeries.test_series_rename
2157+
2158+
Parameters
2159+
-----------
2160+
index : :obj:`scalar` or `hashable sequence` or `dict` or `function`
2161+
Dict-like or functions are transformations to apply to the index.
2162+
Scalar or hashable sequence-like will alter the Series.name attribute.
2163+
Only scalar value is supported.
2164+
copy : :obj:`bool`, default :obj:`True`
2165+
Whether to copy underlying data.
2166+
inplace : :obj:`bool`, default :obj:`False`
2167+
Whether to return a new Series. If True then value of copy is ignored.
2168+
level : :obj:`int` or `str`
2169+
In case of a MultiIndex, only rename labels in the specified level.
2170+
*Not supported*
2171+
Returns
2172+
-------
2173+
:obj:`pandas.Series`
2174+
returns :obj:`pandas.Series` with index labels or name altered.
2175+
"""
2176+
2177+
ty_checker = TypeChecker('Method rename().')
2178+
ty_checker.check(self, SeriesType)
2179+
2180+
if not isinstance(index, (types.Omitted, types.UnicodeType,
2181+
types.StringLiteral, str,
2182+
types.Integer, types.Boolean,
2183+
types.Hashable, types.Float,
2184+
types.NPDatetime, types.NPTimedelta,
2185+
types.Number)) and index is not None:
2186+
ty_checker.raise_exc(index, 'string', 'index')
2187+
2188+
if not isinstance(copy, (types.Omitted, types.Boolean, bool)):
2189+
ty_checker.raise_exc(copy, 'boolean', 'copy')
2190+
2191+
if not isinstance(inplace, (types.Omitted, types.Boolean, bool)):
2192+
ty_checker.raise_exc(inplace, 'boolean', 'inplace')
2193+
2194+
if not isinstance(level, (types.Omitted, types.UnicodeType,
2195+
types.StringLiteral, types.Integer)) and level is not None:
2196+
ty_checker.raise_exc(level, 'Integer or srting', 'level')
2197+
2198+
def hpat_pandas_series_rename_idx_impl(self, index=None, copy=True, inplace=False, level=None):
2199+
if copy is True:
2200+
series_data = self._data.copy()
2201+
series_index = self._index.copy()
2202+
else:
2203+
series_data = self._data
2204+
series_index = self._index
2205+
2206+
return pandas.Series(data=series_data, index=series_index, name=index)
2207+
2208+
def hpat_pandas_series_rename_noidx_impl(self, index=None, copy=True, inplace=False, level=None):
2209+
if copy is True:
2210+
series_data = self._data.copy()
2211+
else:
2212+
series_data = self._data
2213+
2214+
return pandas.Series(data=series_data, index=self._index, name=index)
2215+
2216+
if isinstance(self.index, types.NoneType):
2217+
return hpat_pandas_series_rename_noidx_impl
2218+
return hpat_pandas_series_rename_idx_impl
2219+
2220+
21502221
@overload_method(SeriesType, 'min')
21512222
def hpat_pandas_series_min(self, axis=None, skipna=True, level=None, numeric_only=None):
21522223
"""

sdc/hiframes/hiframes_typed.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -899,15 +899,15 @@ def run_call_series_quantile_default(A):
899899
if func_name == 'dropna':
900900
return self._run_call_series_dropna(assign, lhs, rhs, series_var)
901901

902-
if func_name == 'rename':
903-
nodes = []
904-
data = self._get_series_data(series_var, nodes)
905-
index = self._get_series_index(series_var, nodes)
906-
name = rhs.args[0]
907-
return self._replace_func(
908-
lambda data, index, name: sdc.hiframes.api.init_series(
909-
data, index, name),
910-
[data, index, name], pre_nodes=nodes)
902+
# if func_name == 'rename':
903+
# nodes = []
904+
# data = self._get_series_data(series_var, nodes)
905+
# index = self._get_series_index(series_var, nodes)
906+
# name = rhs.args[0]
907+
# return self._replace_func(
908+
# lambda data, index, name: sdc.hiframes.api.init_series(
909+
# data, index, name),
910+
# [data, index, name], pre_nodes=nodes)
911911

912912
if func_name == 'pct_change':
913913
nodes = []

sdc/hiframes/pd_series_ext.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -729,13 +729,13 @@ def resolve_head(self, ary, args, kws):
729729
# types.int64, types.Array(types.int64, 1, 'C'), ary.data)
730730
# return signature(out, *args)
731731

732-
@bound_function("series.rename")
733-
def resolve_rename(self, ary, args, kws):
734-
# TODO: support index rename, kws
735-
assert len(args) == 1 and isinstance(
736-
args[0], (types.UnicodeType, types.StringLiteral))
737-
out = SeriesType(ary.dtype, ary.data, ary.index, True)
738-
return signature(out, *args)
732+
# @bound_function("series.rename")
733+
# def resolve_rename(self, ary, args, kws):
734+
# # TODO: support index rename, kws
735+
# assert len(args) == 1 and isinstance(
736+
# args[0], (types.UnicodeType, types.StringLiteral))
737+
# out = SeriesType(ary.dtype, ary.data, ary.index, True)
738+
# return signature(out, *args)
739739

740740

741741
# TODO: use ops logic from pandas/core/ops.py

sdc/tests/test_series.py

Lines changed: 89 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,19 +1771,102 @@ def test_impl(S):
17711771
S2 = S1.copy()
17721772
pd.testing.assert_series_equal(hpat_func(S1), test_impl(S2))
17731773

1774-
@unittest.skip('numba.errors.TypingError - fix needed\n'
1775-
'Failed in hpat mode pipeline'
1776-
'(step: convert to distributed)\n'
1777-
'Invalid use of Function(<built-in function len>)'
1778-
'with argument(s) of type(s): (none)\n')
1779-
def test_series_rename1(self):
1774+
def test_series_rename_str_df_noidx(self):
17801775
def test_impl(A):
17811776
return A.rename('B')
17821777
hpat_func = self.jit(test_impl)
17831778

17841779
df = pd.DataFrame({'A': [1.0, 2.0, np.nan, 1.0]})
17851780
pd.testing.assert_series_equal(hpat_func(df.A), test_impl(df.A))
17861781

1782+
def test_series_rename_str_noidx(self):
1783+
def test_impl(S):
1784+
return S.rename('Name')
1785+
jit_func = self.jit(test_impl)
1786+
1787+
S = pd.Series([1, 2, 3])
1788+
pd.testing.assert_series_equal(jit_func(S), test_impl(S))
1789+
1790+
def test_series_rename_str_idx(self):
1791+
def test_impl(S):
1792+
return S.rename('Name')
1793+
jit_func = self.jit(test_impl)
1794+
1795+
S = pd.Series([1, 2, 3], index=['a', 'b', 'c'])
1796+
pd.testing.assert_series_equal(jit_func(S), test_impl(S))
1797+
1798+
def test_series_rename_no_name_str_noidx(self):
1799+
def test_impl(S):
1800+
return S.rename()
1801+
jit_func = self.jit(test_impl)
1802+
1803+
S = pd.Series([1, 2, 3], name='Name')
1804+
pd.testing.assert_series_equal(jit_func(S), test_impl(S))
1805+
1806+
def test_series_rename_no_name_str_idx(self):
1807+
def test_impl(S):
1808+
return S.rename()
1809+
jit_func = self.jit(test_impl)
1810+
1811+
S = pd.Series([1, 2, 3], index=['a', 'b', 'c'], name='Name')
1812+
pd.testing.assert_series_equal(jit_func(S), test_impl(S))
1813+
1814+
def test_series_rename_str_noidx_no_copy(self):
1815+
def test_impl(S):
1816+
return S.rename('Another Name', copy=False)
1817+
jit_func = self.jit(test_impl)
1818+
1819+
S = pd.Series([1, 2, 3], name='Name')
1820+
pd.testing.assert_series_equal(jit_func(S), test_impl(S))
1821+
1822+
def test_series_rename_str_idx_no_copy(self):
1823+
def test_impl(S):
1824+
return S.rename('Another Name', copy=False)
1825+
jit_func = self.jit(test_impl)
1826+
1827+
S = pd.Series([1, 2, 3], index=['a', 'b', 'c'], name='Name')
1828+
pd.testing.assert_series_equal(jit_func(S), test_impl(S))
1829+
1830+
@skip_sdc_jit("Requires full scalar types (not only str) support as Series name")
1831+
@skip_numba_jit("Requires full scalar types (not only str) support as Series name")
1832+
def test_series_rename_int_noidx(self):
1833+
def test_impl(S):
1834+
return S.rename(1)
1835+
jit_func = self.jit(test_impl)
1836+
1837+
S = pd.Series([1, 2, 3], name='Name')
1838+
pd.testing.assert_series_equal(jit_func(S), test_impl(S))
1839+
1840+
@skip_sdc_jit("Requires full scalar types (not only str) support as Series name")
1841+
@skip_numba_jit("Requires full scalar types (not only str) support as Series name")
1842+
def test_series_rename_int_idx(self):
1843+
def test_impl(S):
1844+
return S.rename(1)
1845+
jit_func = self.jit(test_impl)
1846+
1847+
S = pd.Series([1, 2, 3], index=['a', 'b', 'c'], name='Name')
1848+
pd.testing.assert_series_equal(jit_func(S), test_impl(S))
1849+
1850+
@skip_sdc_jit("Requires full scalar types (not only str) support as Series name")
1851+
@skip_numba_jit("Requires full scalar types (not only str) support as Series name")
1852+
def test_series_rename_float_noidx(self):
1853+
def test_impl(S):
1854+
return S.rename(1.1)
1855+
jit_func = self.jit(test_impl)
1856+
1857+
S = pd.Series([1, 2, 3], name='Name')
1858+
pd.testing.assert_series_equal(jit_func(S), test_impl(S))
1859+
1860+
@skip_sdc_jit("Requires full scalar types (not only str) support as Series name")
1861+
@skip_numba_jit("Requires full scalar types (not only str) support as Series name")
1862+
def test_series_rename_float_idx(self):
1863+
def test_impl(S):
1864+
return S.rename(1.1)
1865+
jit_func = self.jit(test_impl)
1866+
1867+
S = pd.Series([1, 2, 3], index=['a', 'b', 'c'], name='Name')
1868+
pd.testing.assert_series_equal(jit_func(S), test_impl(S))
1869+
17871870
def test_series_sum_default(self):
17881871
def test_impl(S):
17891872
return S.sum()

0 commit comments

Comments
 (0)