Skip to content

Commit

Permalink
FIX-#417: Add test for datetime index (#445)
Browse files Browse the repository at this point in the history
* add test for datetime index

* add serialization test

* test using more data

Co-authored-by: Doris Lee <dorisjunglinlee@gmail.com>

* test using more data

Co-authored-by: Doris Lee <dorisjunglinlee@gmail.com>

* fix pre-commit

Co-authored-by: Doris Lee <dorisjunglinlee@gmail.com>
  • Loading branch information
cgarciae and dorisjlee committed Jan 19, 2022
1 parent 726eaca commit 4c95211
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import pytest
import pandas as pd
import numpy as np
from tempfile import TemporaryDirectory
from pathlib import Path


def test_head_tail(global_var):
Expand Down Expand Up @@ -73,3 +75,37 @@ def test_infs():
df = pd.DataFrame({"c1": c1, "c2": c2, "d1": d1, "d2": d2})

df._ipython_display_()


def test_datetime_index():
nrows = 10

# create a datetime index, freq in seconds
dt = pd.date_range("1/1/2019", periods=nrows, freq="1s")

# continuous
c1 = np.random.uniform(0, 1, size=nrows)

data = np.random.uniform(0, 1, size=(nrows, 50))
df = pd.DataFrame(data, index=dt)

df._ipython_display_()


def test_datetime_index_serialize():
nrows = 100000

# create a datetime index, freq in seconds
dt = pd.date_range("1/1/2019", periods=nrows, freq="1s")

# continuous
c1 = np.random.uniform(0, 1, size=nrows)

df = pd.DataFrame({"c1": c1}, index=dt)

with TemporaryDirectory() as tmpdir:
tmpdir = Path(tmpdir)
df.to_csv(tmpdir / "test.csv")
df = pd.read_csv(tmpdir / "test.csv", names=["date", "c1"], index_col="date", header=0)

df._ipython_display_()

0 comments on commit 4c95211

Please sign in to comment.