|
1 | 1 | # -*- coding: utf-8 -*-
|
2 | 2 |
|
3 |
| -from __future__ import print_function |
4 |
| - |
5 |
| -from numpy import nan |
| 3 | +import pytest |
6 | 4 | import numpy as np
|
7 | 5 |
|
8 | 6 | from pandas import compat
|
9 | 7 | from pandas import (DataFrame, Series, MultiIndex, Timestamp,
|
10 | 8 | date_range)
|
11 | 9 |
|
12 | 10 | import pandas.util.testing as tm
|
13 |
| - |
14 | 11 | from pandas.tests.frame.common import TestData
|
15 | 12 |
|
16 | 13 |
|
@@ -41,13 +38,13 @@ def test_to_dict(self):
|
41 | 38 |
|
42 | 39 | recons_data = DataFrame(test_data).to_dict("sp")
|
43 | 40 | expected_split = {'columns': ['A', 'B'], 'index': ['1', '2', '3'],
|
44 |
| - 'data': [[1.0, '1'], [2.0, '2'], [nan, '3']]} |
| 41 | + 'data': [[1.0, '1'], [2.0, '2'], [np.nan, '3']]} |
45 | 42 | tm.assert_dict_equal(recons_data, expected_split)
|
46 | 43 |
|
47 | 44 | recons_data = DataFrame(test_data).to_dict("r")
|
48 | 45 | expected_records = [{'A': 1.0, 'B': '1'},
|
49 | 46 | {'A': 2.0, 'B': '2'},
|
50 |
| - {'A': nan, 'B': '3'}] |
| 47 | + {'A': np.nan, 'B': '3'}] |
51 | 48 | tm.assertIsInstance(recons_data, list)
|
52 | 49 | self.assertEqual(len(recons_data), 3)
|
53 | 50 | for l, r in zip(recons_data, expected_records):
|
@@ -192,3 +189,18 @@ def test_to_records_with_unicode_column_names(self):
|
192 | 189 | "formats": ['<i8', '<f8']}
|
193 | 190 | )
|
194 | 191 | tm.assert_almost_equal(result, expected)
|
| 192 | + |
| 193 | + |
| 194 | +@pytest.mark.parametrize('tz', ['UTC', 'GMT', 'US/Eastern']) |
| 195 | +def test_to_records_datetimeindex_with_tz(tz): |
| 196 | + # GH13937 |
| 197 | + dr = date_range('2016-01-01', periods=10, |
| 198 | + freq='S', tz=tz) |
| 199 | + |
| 200 | + df = DataFrame({'datetime': dr}, index=dr) |
| 201 | + |
| 202 | + expected = df.to_records() |
| 203 | + result = df.tz_convert("UTC").to_records() |
| 204 | + |
| 205 | + # both converted to UTC, so they are equal |
| 206 | + tm.assert_numpy_array_equal(result, expected) |
0 commit comments