def test_json_conversion_strings_with_leading_zeros(): runner_ids = np.array(['000000000' + str(x) for x in range(10)]) df = DDF({'runner_id': runner_ids}) js = df.to_json() newdf = DDF.from_json(js) newdf = newdf.colslice(df) assert newdf.equals(df)
def test_to_json(df): with pytest.raises(AssertionError): df.to_json() df = df.rename(lambda col: str(col)) df = df.sort('0') json = df.to_json() newdf = DDF.from_json(json) newdf = newdf.sort('0') assert newdf.equals(df)
def test_json_conversion_preserves_string_dtypes(): original_df = DDF({ 'runner_id': np.array(['test', 'testing'], dtype='S7'), 'short_strings': np.array(['a', 'b'], dtype='S1'), 'more_strings': np.array(['abc', 'def'], dtype='S') }) js = original_df.to_json() new_df = DDF.from_json(js) new_df = new_df.colslice(original_df) assert new_df.equals(original_df) for col in ['runner_id', 'short_strings', 'more_strings']: assert new_df[col].dtype == original_df[col].dtype
def test_json_conversion_datetimes(): dates = np.array([ '2013-03-30T00:00:00.000000000', '2014-02-10T00:00:00.000000000', '2014-05-12T00:00:00.000000000', '2014-03-17T00:00:00.000000000', '2013-04-12T00:00:00.000000000', '2014-05-19T00:00:00.000000000', '2014-04-09T00:00:00.000000000', '2014-05-11T00:00:00.000000000', '2014-02-25T00:00:00.000000000', '2014-04-24T00:00:00.000000000', '2014-05-30T00:00:00.000000000', '2014-02-09T00:00:00.000000000', '2014-05-05T00:00:00.000000000'], dtype='<M8[ns]') df = DDF({'time': dates}) js = df.to_json() newdf = DDF.from_json(js) newdf = newdf.colslice(df) assert newdf.equals(df)