def test_convert_sql_column_bools(self): arr = np.array([True, False, True, False], dtype='O') result = lib.convert_sql_column(arr) expected = np.array([True, False, True, False], dtype=bool) assert_same_values_and_dtype(result, expected) arr = np.array([True, False, None, False], dtype='O') result = lib.convert_sql_column(arr) expected = np.array([True, False, np.nan, False], dtype=object) assert_same_values_and_dtype(result, expected)
def test_convert_sql_column_longs(self): arr = np.array([1L, 2L, 3L, 4L], dtype="O") result = lib.convert_sql_column(arr) expected = np.array([1, 2, 3, 4], dtype="i8") assert_same_values_and_dtype(result, expected) arr = np.array([1L, 2L, 3L, None, 4L], dtype="O") result = lib.convert_sql_column(arr) expected = np.array([1, 2, 3, np.nan, 4], dtype="f8") assert_same_values_and_dtype(result, expected)
def test_convert_sql_column_longs(self): arr = np.array([1L, 2L, 3L, 4L], dtype='O') result = lib.convert_sql_column(arr) expected = np.array([1, 2, 3, 4], dtype='i8') assert_same_values_and_dtype(result, expected) arr = np.array([1L, 2L, 3L, None, 4L], dtype='O') result = lib.convert_sql_column(arr) expected = np.array([1, 2, 3, np.nan, 4], dtype='f8') assert_same_values_and_dtype(result, expected)
def test_convert_sql_column_bools(self): arr = np.array([True, False, True, False], dtype="O") result = lib.convert_sql_column(arr) expected = np.array([True, False, True, False], dtype=bool) assert_same_values_and_dtype(result, expected) arr = np.array([True, False, None, False], dtype="O") result = lib.convert_sql_column(arr) expected = np.array([True, False, np.nan, False], dtype=object) assert_same_values_and_dtype(result, expected)
def test_convert_sql_column_ints(self): arr = np.array([1, 2, 3, 4], dtype='O') arr2 = np.array([1, 2, 3, 4], dtype='i4').astype('O') result = lib.convert_sql_column(arr) result2 = lib.convert_sql_column(arr2) expected = np.array([1, 2, 3, 4], dtype='i8') assert_same_values_and_dtype(result, expected) assert_same_values_and_dtype(result2, expected) arr = np.array([1, 2, 3, None, 4], dtype='O') result = lib.convert_sql_column(arr) expected = np.array([1, 2, 3, np.nan, 4], dtype='f8') assert_same_values_and_dtype(result, expected)
def test_convert_sql_column_ints(self): arr = np.array([1, 2, 3, 4], dtype="O") arr2 = np.array([1, 2, 3, 4], dtype="i4").astype("O") result = lib.convert_sql_column(arr) result2 = lib.convert_sql_column(arr2) expected = np.array([1, 2, 3, 4], dtype="i8") assert_same_values_and_dtype(result, expected) assert_same_values_and_dtype(result2, expected) arr = np.array([1, 2, 3, None, 4], dtype="O") result = lib.convert_sql_column(arr) expected = np.array([1, 2, 3, np.nan, 4], dtype="f8") assert_same_values_and_dtype(result, expected)
def test_convert_sql_column_decimals(self): from decimal import Decimal arr = np.array([Decimal("1.5"), None, Decimal("3"), Decimal("4.2")]) result = lib.convert_sql_column(arr) expected = np.array([1.5, np.nan, 3, 4.2], dtype="f8") assert_same_values_and_dtype(result, expected)
def list_to_dataframe(rows, names): import pandas._tseries as lib from pandas import DataFrame if isinstance(rows, tuple): rows = list(rows) columns = dict(zip(names, lib.to_object_array_tuples(rows).T)) for k, v in columns.iteritems(): columns[k] = lib.convert_sql_column(v) return DataFrame(columns, columns=names)
def list_to_dataframe(rows, names): """ Turns a rows of data into a dataframe and gives them the column names specified :params rows: the data you want to put in the dataframe :params names: the column names for the dataframe """ from pandas import DataFrame try: import pandas._tseries as lib except ImportError: import pandas.lib as lib if isinstance(rows, tuple): rows = list(rows) columns = dict(zip(names, lib.to_object_array_tuples(rows).T)) for k, v in columns.iteritems(): columns[k] = lib.convert_sql_column(v) return DataFrame(columns, columns=names)
def test_convert_sql_column_strings(self): arr = np.array(['1.5', None, '3', '4.2'], dtype=object) result = lib.convert_sql_column(arr) expected = np.array(['1.5', np.nan, '3', '4.2'], dtype=object) assert_same_values_and_dtype(result, expected)
def test_convert_sql_column_floats(self): arr = np.array([1.5, None, 3, 4.2], dtype=object) result = lib.convert_sql_column(arr) expected = np.array([1.5, np.nan, 3, 4.2], dtype='f8') assert_same_values_and_dtype(result, expected)
def test_convert_sql_column_unicode(self): arr = np.array([u'1.5', None, u'3', u'4.2'], dtype=object) result = lib.convert_sql_column(arr) expected = np.array([u'1.5', np.nan, u'3', u'4.2'], dtype=object) assert_same_values_and_dtype(result, expected)
def test_convert_sql_column_unicode(self): arr = np.array([u"1.5", None, u"3", u"4.2"], dtype=object) result = lib.convert_sql_column(arr) expected = np.array([u"1.5", np.nan, u"3", u"4.2"], dtype=object) assert_same_values_and_dtype(result, expected)
def test_convert_sql_column_strings(self): arr = np.array(["1.5", None, "3", "4.2"], dtype=object) result = lib.convert_sql_column(arr) expected = np.array(["1.5", np.nan, "3", "4.2"], dtype=object) assert_same_values_and_dtype(result, expected)
def test_convert_sql_column_floats(self): arr = np.array([1.5, None, 3, 4.2], dtype=object) result = lib.convert_sql_column(arr) expected = np.array([1.5, np.nan, 3, 4.2], dtype="f8") assert_same_values_and_dtype(result, expected)
def test_convert_sql_column_decimals(self): from decimal import Decimal arr = np.array([Decimal('1.5'), None, Decimal('3'), Decimal('4.2')]) result = lib.convert_sql_column(arr) expected = np.array([1.5, np.nan, 3, 4.2], dtype='f8') assert_same_values_and_dtype(result, expected)