@@ -365,6 +365,38 @@ def _guess_bounds_dim(da):
365
365
return result
366
366
367
367
368
+ def _build_docstring (func ):
369
+ """
370
+ Builds a nice docstring for wrapped functions, stating what key words
371
+ can be used for arguments.
372
+ """
373
+
374
+ # this list will need to be updated any time a new mapper is added
375
+ mapper_docstrings = {
376
+ _get_axis_coord : f"One or more of { (_AXIS_NAMES + _COORD_NAMES )!r} " ,
377
+ _get_axis_coord_single : f"One of { (_AXIS_NAMES + _COORD_NAMES )!r} " ,
378
+ _get_measure_variable : f"One of { _CELL_MEASURES !r} " ,
379
+ }
380
+
381
+ sig = inspect .signature (func )
382
+ string = ""
383
+ for k in set (sig .parameters .keys ()) & set (_DEFAULT_KEY_MAPPERS ):
384
+ mappers = _DEFAULT_KEY_MAPPERS .get (k , [])
385
+ docstring = "; " .join (
386
+ mapper_docstrings .get (mapper , "unknown. please open an issue." )
387
+ for mapper in mappers
388
+ )
389
+ string += f"\t \t { k } : { docstring } \n "
390
+
391
+ for param in sig .parameters :
392
+ if sig .parameters [param ].kind is inspect .Parameter .VAR_KEYWORD :
393
+ string += f"\t \t { param } : { mapper_docstrings [_get_axis_coord ]} \n \n "
394
+ return (
395
+ f"\n \t The following arguments will be processed by cf_xarray: \n { string } "
396
+ "\n \t ----\n \t "
397
+ )
398
+
399
+
368
400
def _getattr (
369
401
obj : Union [DataArray , Dataset ],
370
402
attr : str ,
@@ -443,6 +475,8 @@ def wrapper(*args, **kwargs):
443
475
444
476
return result
445
477
478
+ wrapper .__doc__ = _build_docstring (func ) + wrapper .__doc__
479
+
446
480
return wrapper
447
481
448
482
0 commit comments