MCPcopy Create free account
hub / github.com/apache/arrow / _column_name_to_strings

Function _column_name_to_strings

python/pyarrow/pandas_compat.py:326–362  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

324
325
326def _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
365def _index_level_name(index, i, column_names):

Callers 4

construct_metadataFunction · 0.85
_index_level_nameFunction · 0.85
_get_columns_to_convertFunction · 0.85

Calls 3

mapFunction · 0.85
TypeErrorFunction · 0.50
decodeMethod · 0.45

Tested by

no test coverage detected