Convert a column name (or level) to either a string or a recursive collection of strings. Parameters ---------- name : str or tuple Returns ------- value : str or tuple Examples -------- >>> name = 'foo' >>> _column_name_to_strings(name) 'foo' >
(name)
| 324 | |
| 325 | |
| 326 | def _column_name_to_strings(name): |
| 327 | """Convert a column name (or level) to either a string or a recursive |
| 328 | collection of strings. |
| 329 | |
| 330 | Parameters |
| 331 | ---------- |
| 332 | name : str or tuple |
| 333 | |
| 334 | Returns |
| 335 | ------- |
| 336 | value : str or tuple |
| 337 | |
| 338 | Examples |
| 339 | -------- |
| 340 | >>> name = 'foo' |
| 341 | >>> _column_name_to_strings(name) |
| 342 | 'foo' |
| 343 | >>> name = ('foo', 'bar') |
| 344 | >>> _column_name_to_strings(name) |
| 345 | "('foo', 'bar')" |
| 346 | >>> import pandas as pd |
| 347 | >>> name = (1, pd.Timestamp('2017-02-01 00:00:00')) |
| 348 | >>> _column_name_to_strings(name) |
| 349 | "('1', '2017-02-01 00:00:00')" |
| 350 | """ |
| 351 | if isinstance(name, str): |
| 352 | return name |
| 353 | elif isinstance(name, bytes): |
| 354 | # XXX: should we assume that bytes in Python 3 are UTF-8? |
| 355 | return name.decode('utf8') |
| 356 | elif isinstance(name, tuple): |
| 357 | return str(tuple(map(_column_name_to_strings, name))) |
| 358 | elif isinstance(name, Sequence): |
| 359 | raise TypeError("Unsupported type for MultiIndex level") |
| 360 | elif name is None or (isinstance(name, float) and np.isnan(name)): |
| 361 | return name |
| 362 | return str(name) |
| 363 | |
| 364 | |
| 365 | def _index_level_name(index, i, column_names): |
no test coverage detected