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

Class Map

dask/dataframe/dask_expr/_expr.py:1851–1905  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1849
1850
1851class Map(Elemwise):
1852 _projection_passthrough = True
1853 _parameters = ["frame", "arg", "na_action", "meta", "is_monotonic"]
1854 _defaults = {"na_action": None, "meta": None, "is_monotonic": True}
1855 _keyword_only = ["meta", "is_monotonic"]
1856 operation = M.map
1857
1858 @functools.cached_property
1859 def _meta(self):
1860 if self.operand("meta") is None:
1861 args = [
1862 meta_nonempty(op._meta) if isinstance(op, Expr) else op
1863 for op in self._args
1864 ]
1865 return make_meta(self.operation(*args, **self._kwargs))
1866 return make_meta(
1867 self.operand("meta"),
1868 parent_meta=self.frame._meta,
1869 index=getattr(self.frame._meta, "index", None), # could be an index
1870 )
1871
1872 @functools.cached_property
1873 def _kwargs(self) -> dict:
1874 return {}
1875
1876 def _broadcast_dep(self, dep: Expr):
1877 if (
1878 dep.npartitions == 1
1879 and isinstance(self.operand("arg"), Expr)
1880 and dep is self.operand("arg")
1881 ):
1882 return True
1883 return super()._broadcast_dep(dep)
1884
1885 def _divisions(self):
1886 if not self.is_monotonic:
1887 # Implement this consistently with dask.dataframe, e.g. add option to
1888 # control monotonic map func
1889 return (None,) * len(self.frame.divisions)
1890 elif is_index_like(self.frame._meta):
1891 if isinstance(self.arg, Expr):
1892 return (None,) * len(self.frame.divisions)
1893 return tuple(
1894 pd.Series(self.frame.divisions).map(self.arg, na_action=self.na_action)
1895 )
1896 elif isinstance(self.arg, Expr):
1897 if (
1898 self._broadcast_dep(self.arg)
1899 or self.arg.divisions == self.frame.divisions
1900 ):
1901 return self.frame.divisions
1902 else:
1903 # We only get here when we have only one partition
1904 return (None,) * (self.frame.npartitions + 1)
1905 return super()._divisions()
1906
1907
1908class VarColumns(Elemwise):

Callers 1

_lowerMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected