|
20 | 20 | CountMode,
|
21 | 21 | ImageFormat,
|
22 | 22 | ImageMode,
|
| 23 | + ImageProperty, |
23 | 24 | ResourceRequest,
|
24 | 25 | initialize_udfs,
|
25 | 26 | resolved_col,
|
@@ -5224,6 +5225,60 @@ def to_mode(self, mode: str | ImageMode) -> Expression:
|
5224 | 5225 | f = native.get_function_from_registry("to_mode")
|
5225 | 5226 | return Expression._from_pyexpr(f(self._expr, mode=image_mode))
|
5226 | 5227 |
|
| 5228 | + def attribute(self, name: Literal["width", "height", "channel", "mode"] | ImageProperty) -> Expression: |
| 5229 | + """Get a property of the image, such as 'width', 'height', 'channel', or 'mode'. |
| 5230 | +
|
| 5231 | + Args: |
| 5232 | + name (str): The name of the property to retrieve. |
| 5233 | +
|
| 5234 | + Returns: |
| 5235 | + Expression: An Expression representing the requested property. |
| 5236 | + """ |
| 5237 | + if isinstance(name, str): |
| 5238 | + name = ImageProperty.from_property_string(name) |
| 5239 | + f = native.get_function_from_registry("image_attribute") |
| 5240 | + return Expression._from_pyexpr(f(self._expr, lit(name)._expr)) |
| 5241 | + |
| 5242 | + def width(self) -> Expression: |
| 5243 | + """Gets the width of an image in pixels. |
| 5244 | +
|
| 5245 | + Example: |
| 5246 | + >>> # Create a dataframe with an image column |
| 5247 | + >>> df = ... # doctest: +SKIP |
| 5248 | + >>> df = df.with_column("width", df["images"].image.width()) # doctest: +SKIP |
| 5249 | + """ |
| 5250 | + return self.attribute("width") |
| 5251 | + |
| 5252 | + def height(self) -> Expression: |
| 5253 | + """Gets the height of an image in pixels. |
| 5254 | +
|
| 5255 | + Example: |
| 5256 | + >>> # Create a dataframe with an image column |
| 5257 | + >>> df = ... # doctest: +SKIP |
| 5258 | + >>> df = df.with_column("height", df["images"].image.height()) # doctest: +SKIP |
| 5259 | + """ |
| 5260 | + return self.attribute("height") |
| 5261 | + |
| 5262 | + def channel(self) -> Expression: |
| 5263 | + """Gets the number of channels in an image. |
| 5264 | +
|
| 5265 | + Example: |
| 5266 | + >>> # Create a dataframe with an image column |
| 5267 | + >>> df = ... # doctest: +SKIP |
| 5268 | + >>> df = df.with_column("channel", df["images"].image.channel()) # doctest: +SKIP |
| 5269 | + """ |
| 5270 | + return self.attribute("channel") |
| 5271 | + |
| 5272 | + def mode(self) -> Expression: |
| 5273 | + """Gets the mode of an image as a string. |
| 5274 | +
|
| 5275 | + Example: |
| 5276 | + >>> # Create a dataframe with an image column |
| 5277 | + >>> df = ... # doctest: +SKIP |
| 5278 | + >>> df = df.with_column("mode", df["images"].image.mode()) # doctest: +SKIP |
| 5279 | + """ |
| 5280 | + return self.attribute("mode") |
| 5281 | + |
5227 | 5282 |
|
5228 | 5283 | class ExpressionPartitioningNamespace(ExpressionNamespace):
|
5229 | 5284 | """The following methods are available under the `expr.partition` attribute."""
|
|
0 commit comments