Skip to content

TST: add read_json test for issue #32383 #33344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion pandas/tests/indexes/datetimes/test_datetime.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import date
from datetime import date, timedelta

import dateutil
import numpy as np
Expand Down Expand Up @@ -44,6 +44,45 @@ def test_reindex_preserves_tz_if_target_is_empty_list_or_array(self):
assert str(index.reindex([])[0].tz) == "US/Eastern"
assert str(index.reindex(np.array([]))[0].tz) == "US/Eastern"

def test_reindex_with_same_tz(self):
# GH 32740
rng_a = date_range("2010-01-01", "2010-01-02", periods=24, tz="utc")
rng_b = date_range("2010-01-01", "2010-01-02", periods=23, tz="utc")
result1, result2 = rng_a.reindex(
rng_b, method="nearest", tolerance=timedelta(seconds=20)
)
expected_list1 = [
"2010-01-01 00:00:00",
"2010-01-01 01:05:27.272727272",
"2010-01-01 02:10:54.545454545",
"2010-01-01 03:16:21.818181818",
"2010-01-01 04:21:49.090909090",
"2010-01-01 05:27:16.363636363",
"2010-01-01 06:32:43.636363636",
"2010-01-01 07:38:10.909090909",
"2010-01-01 08:43:38.181818181",
"2010-01-01 09:49:05.454545454",
"2010-01-01 10:54:32.727272727",
"2010-01-01 12:00:00",
"2010-01-01 13:05:27.272727272",
"2010-01-01 14:10:54.545454545",
"2010-01-01 15:16:21.818181818",
"2010-01-01 16:21:49.090909090",
"2010-01-01 17:27:16.363636363",
"2010-01-01 18:32:43.636363636",
"2010-01-01 19:38:10.909090909",
"2010-01-01 20:43:38.181818181",
"2010-01-01 21:49:05.454545454",
"2010-01-01 22:54:32.727272727",
"2010-01-02 00:00:00",
]
expected1 = DatetimeIndex(
expected_list1, dtype="datetime64[ns, UTC]", freq=None,
)
expected2 = np.array([0] + [-1] * 21 + [23], dtype=np.int64,)
tm.assert_index_equal(result1, expected1)
tm.assert_numpy_array_equal(result2, expected2)

def test_time_loc(self): # GH8667
from datetime import time
from pandas._libs.index import _SIZE_CUTOFF
Expand Down
16 changes: 16 additions & 0 deletions pandas/tests/io/json/test_json_table_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,22 @@ def test_build_series(self):

assert result == expected

def test_read_json(self):
df = pd.DataFrame(
{
"_id": {"0": "0"},
"category": {"0": "Goods"},
"recommender_id": {"0": "3"},
"recommender_name_en": {"0": "Urata"},
"name_en": {"0": "Hakata Dolls Matsuo"},
}
)
df_json = df.to_json()
df_dict = json.loads(df_json)
result = pd.read_json(df_json)
expected = pd.DataFrame().from_dict(df_dict)
tm.assert_frame_equal(result, expected)

def test_to_json(self):
df = self.df.copy()
df.index.name = "idx"
Expand Down