Assuming x is list-like or even an existing Series, returns a new Series named `name`.
(x, name=None, native_namespace=None)
| 1192 | |
| 1193 | |
| 1194 | def to_named_series(x, name=None, native_namespace=None): |
| 1195 | """Assuming x is list-like or even an existing Series, returns a new Series named `name`.""" |
| 1196 | # With `pass_through=True`, the original object will be returned if unable to convert |
| 1197 | # to a Narwhals Series. |
| 1198 | x = nw.from_native(x, series_only=True, pass_through=True) |
| 1199 | if isinstance(x, nw.Series): |
| 1200 | return x.rename(name) |
| 1201 | elif native_namespace is not None: |
| 1202 | return nw.new_series(name=name, values=x, native_namespace=native_namespace) |
| 1203 | else: |
| 1204 | try: |
| 1205 | import pandas as pd |
| 1206 | |
| 1207 | return nw.new_series(name=name, values=x, native_namespace=pd) |
| 1208 | except ImportError: |
| 1209 | msg = "Pandas installation is required if no dataframe is provided." |
| 1210 | raise NotImplementedError(msg) |
| 1211 | |
| 1212 | |
| 1213 | def process_args_into_dataframe( |
no outgoing calls
no test coverage detected