5
5
if TYPE_CHECKING :
6
6
from typing_extensions import Self
7
7
8
+ from dataframe_api .dataframe_object import DataFrame
9
+
8
10
from .typing import DType , Namespace , NullType , Scalar
9
11
10
12
@@ -17,9 +19,45 @@ class Column(Protocol):
17
19
Note that this column object is not meant to be instantiated directly by
18
20
users of the library implementing the dataframe API standard. Rather, use
19
21
constructor functions or an already-created dataframe object retrieved via
20
-
22
+ :meth:`DataFrame.col`.
23
+
24
+ The parent dataframe (which can be retrieved via the :meth:`parent_dataframe`
25
+ property) plays a key role here:
26
+
27
+ - If two columns were retrieved from the same dataframe,
28
+ then they can be combined and compared at will.
29
+ - If two columns were retrieved from different dataframes,
30
+ then there is no guarantee about how or whether they can be combined and
31
+ compared, this may vary across implementations.
32
+ - If two columns are both "free-standing" (i.e. not retrieved from a dataframe
33
+ but constructed directly from a 1D array or sequence), then they can be
34
+ combined and compared with each other. Note, however, that there's no guarantee
35
+ about whether they can be compared or combined with columns retrieved from a
36
+ different dataframe, this may vary across implementations.
21
37
"""
22
38
39
+ @property
40
+ def parent_dataframe (self ) -> DataFrame | None :
41
+ """Return parent DataFrame, if present.
42
+
43
+ For example, if we have the following
44
+
45
+ .. code-block:: python
46
+
47
+ df: DataFrame
48
+ column = df.col('a')
49
+
50
+ then `column.parent_dataframe` should return `df`.
51
+
52
+ On the other hand, if we had:
53
+
54
+ .. code-block:: python
55
+
56
+ column = column_from_1d_array(...)
57
+
58
+ then `column.parent_dataframe` should return `None`.
59
+ """
60
+
23
61
def __column_namespace__ (self ) -> Namespace :
24
62
"""Return an object that has all the Dataframe Standard API functions on it.
25
63
@@ -201,6 +239,11 @@ def __eq__(self, other: Self | Scalar) -> Self: # type: ignore[override]
201
239
Returns
202
240
-------
203
241
Column
242
+
243
+ Notes
244
+ -----
245
+ `other`'s parent DataFrame must be the same as `self`'s - else,
246
+ the operation is unsupported and may vary across implementations.
204
247
"""
205
248
...
206
249
@@ -219,6 +262,11 @@ def __ne__(self, other: Self | Scalar) -> Self: # type: ignore[override]
219
262
Returns
220
263
-------
221
264
Column
265
+
266
+ Notes
267
+ -----
268
+ `other`'s parent DataFrame must be the same as `self`'s - else,
269
+ the operation is unsupported and may vary across implementations.
222
270
"""
223
271
...
224
272
@@ -235,6 +283,11 @@ def __ge__(self, other: Self | Scalar) -> Self:
235
283
Returns
236
284
-------
237
285
Column
286
+
287
+ Notes
288
+ -----
289
+ `other`'s parent DataFrame must be the same as `self`'s - else,
290
+ the operation is unsupported and may vary across implementations.
238
291
"""
239
292
...
240
293
@@ -251,6 +304,11 @@ def __gt__(self, other: Self | Scalar) -> Self:
251
304
Returns
252
305
-------
253
306
Column
307
+
308
+ Notes
309
+ -----
310
+ `other`'s parent DataFrame must be the same as `self`'s - else,
311
+ the operation is unsupported and may vary across implementations.
254
312
"""
255
313
...
256
314
@@ -267,6 +325,11 @@ def __le__(self, other: Self | Scalar) -> Self:
267
325
Returns
268
326
-------
269
327
Column
328
+
329
+ Notes
330
+ -----
331
+ `other`'s parent DataFrame must be the same as `self`'s - else,
332
+ the operation is unsupported and may vary across implementations.
270
333
"""
271
334
...
272
335
@@ -283,6 +346,11 @@ def __lt__(self, other: Self | Scalar) -> Self:
283
346
Returns
284
347
-------
285
348
Column
349
+
350
+ Notes
351
+ -----
352
+ `other`'s parent DataFrame must be the same as `self`'s - else,
353
+ the operation is unsupported and may vary across implementations.
286
354
"""
287
355
...
288
356
@@ -300,6 +368,11 @@ def __and__(self, other: Self | bool) -> Self:
300
368
-------
301
369
Column
302
370
371
+ Notes
372
+ -----
373
+ `other`'s parent DataFrame must be the same as `self`'s - else,
374
+ the operation is unsupported and may vary across implementations.
375
+
303
376
Raises
304
377
------
305
378
ValueError
@@ -321,6 +394,11 @@ def __or__(self, other: Self | bool) -> Self:
321
394
-------
322
395
Column
323
396
397
+ Notes
398
+ -----
399
+ `other`'s parent DataFrame must be the same as `self`'s - else,
400
+ the operation is unsupported and may vary across implementations.
401
+
324
402
Raises
325
403
------
326
404
ValueError
@@ -338,6 +416,11 @@ def __add__(self, other: Self | Scalar) -> Self:
338
416
"Scalar" here is defined implicitly by what scalar types are allowed
339
417
for the operation by the underling dtypes.
340
418
419
+ Notes
420
+ -----
421
+ `other`'s parent DataFrame must be the same as `self`'s - else,
422
+ the operation is unsupported and may vary across implementations.
423
+
341
424
Returns
342
425
-------
343
426
Column
@@ -357,6 +440,11 @@ def __sub__(self, other: Self | Scalar) -> Self:
357
440
Returns
358
441
-------
359
442
Column
443
+
444
+ Notes
445
+ -----
446
+ `other`'s parent DataFrame must be the same as `self`'s - else,
447
+ the operation is unsupported and may vary across implementations.
360
448
"""
361
449
...
362
450
@@ -373,6 +461,11 @@ def __mul__(self, other: Self | Scalar) -> Self:
373
461
Returns
374
462
-------
375
463
Column
464
+
465
+ Notes
466
+ -----
467
+ `other`'s parent DataFrame must be the same as `self`'s - else,
468
+ the operation is unsupported and may vary across implementations.
376
469
"""
377
470
...
378
471
@@ -389,6 +482,11 @@ def __truediv__(self, other: Self | Scalar) -> Self:
389
482
Returns
390
483
-------
391
484
Column
485
+
486
+ Notes
487
+ -----
488
+ `other`'s parent DataFrame must be the same as `self`'s - else,
489
+ the operation is unsupported and may vary across implementations.
392
490
"""
393
491
...
394
492
@@ -405,6 +503,11 @@ def __floordiv__(self, other: Self | Scalar) -> Self:
405
503
Returns
406
504
-------
407
505
Column
506
+
507
+ Notes
508
+ -----
509
+ `other`'s parent DataFrame must be the same as `self`'s - else,
510
+ the operation is unsupported and may vary across implementations.
408
511
"""
409
512
...
410
513
@@ -425,6 +528,11 @@ def __pow__(self, other: Self | Scalar) -> Self:
425
528
Returns
426
529
-------
427
530
Column
531
+
532
+ Notes
533
+ -----
534
+ `other`'s parent DataFrame must be the same as `self`'s - else,
535
+ the operation is unsupported and may vary across implementations.
428
536
"""
429
537
...
430
538
@@ -441,6 +549,11 @@ def __mod__(self, other: Self | Scalar) -> Self:
441
549
Returns
442
550
-------
443
551
Column
552
+
553
+ Notes
554
+ -----
555
+ `other`'s parent DataFrame must be the same as `self`'s - else,
556
+ the operation is unsupported and may vary across implementations.
444
557
"""
445
558
...
446
559
@@ -457,6 +570,11 @@ def __divmod__(self, other: Self | Scalar) -> tuple[Column, Column]:
457
570
Returns
458
571
-------
459
572
Column
573
+
574
+ Notes
575
+ -----
576
+ `other`'s parent DataFrame must be the same as `self`'s - else,
577
+ the operation is unsupported and may vary across implementations.
460
578
"""
461
579
...
462
580
0 commit comments