|
1 |
| -import numpy as np |
2 |
| - |
3 |
| -from pandas.util._decorators import cache_readonly |
4 |
| - |
5 |
| -import pandas as pd |
6 |
| -import pandas.util.testing as tm |
7 |
| - |
8 |
| -_seriesd = tm.getSeriesData() |
9 |
| -_tsd = tm.getTimeSeriesData() |
10 |
| - |
11 |
| -_frame = pd.DataFrame(_seriesd) |
12 |
| -_frame2 = pd.DataFrame(_seriesd, columns=["D", "C", "B", "A"]) |
13 |
| -_intframe = pd.DataFrame({k: v.astype(int) for k, v in _seriesd.items()}) |
14 |
| - |
15 |
| -_tsframe = pd.DataFrame(_tsd) |
16 |
| - |
17 |
| -_mixed_frame = _frame.copy() |
18 |
| -_mixed_frame["foo"] = "bar" |
19 |
| - |
20 |
| - |
21 |
| -class TestData: |
22 |
| - @cache_readonly |
23 |
| - def frame(self): |
24 |
| - return _frame.copy() |
25 |
| - |
26 |
| - @cache_readonly |
27 |
| - def frame2(self): |
28 |
| - return _frame2.copy() |
29 |
| - |
30 |
| - @cache_readonly |
31 |
| - def intframe(self): |
32 |
| - # force these all to int64 to avoid platform testing issues |
33 |
| - return pd.DataFrame({c: s for c, s in _intframe.items()}, dtype=np.int64) |
34 |
| - |
35 |
| - @cache_readonly |
36 |
| - def tsframe(self): |
37 |
| - return _tsframe.copy() |
38 |
| - |
39 |
| - @cache_readonly |
40 |
| - def mixed_frame(self): |
41 |
| - return _mixed_frame.copy() |
42 |
| - |
43 |
| - @cache_readonly |
44 |
| - def mixed_float(self): |
45 |
| - return pd.DataFrame( |
46 |
| - { |
47 |
| - "A": _frame["A"].copy().astype("float32"), |
48 |
| - "B": _frame["B"].copy().astype("float32"), |
49 |
| - "C": _frame["C"].copy().astype("float16"), |
50 |
| - "D": _frame["D"].copy().astype("float64"), |
51 |
| - } |
52 |
| - ) |
53 |
| - |
54 |
| - @cache_readonly |
55 |
| - def mixed_float2(self): |
56 |
| - return pd.DataFrame( |
57 |
| - { |
58 |
| - "A": _frame2["A"].copy().astype("float32"), |
59 |
| - "B": _frame2["B"].copy().astype("float32"), |
60 |
| - "C": _frame2["C"].copy().astype("float16"), |
61 |
| - "D": _frame2["D"].copy().astype("float64"), |
62 |
| - } |
63 |
| - ) |
64 |
| - |
65 |
| - @cache_readonly |
66 |
| - def mixed_int(self): |
67 |
| - return pd.DataFrame( |
68 |
| - { |
69 |
| - "A": _intframe["A"].copy().astype("int32"), |
70 |
| - "B": np.ones(len(_intframe["B"]), dtype="uint64"), |
71 |
| - "C": _intframe["C"].copy().astype("uint8"), |
72 |
| - "D": _intframe["D"].copy().astype("int64"), |
73 |
| - } |
74 |
| - ) |
75 |
| - |
76 |
| - @cache_readonly |
77 |
| - def all_mixed(self): |
78 |
| - return pd.DataFrame( |
79 |
| - { |
80 |
| - "a": 1.0, |
81 |
| - "b": 2, |
82 |
| - "c": "foo", |
83 |
| - "float32": np.array([1.0] * 10, dtype="float32"), |
84 |
| - "int32": np.array([1] * 10, dtype="int32"), |
85 |
| - }, |
86 |
| - index=np.arange(10), |
87 |
| - ) |
88 |
| - |
89 |
| - @cache_readonly |
90 |
| - def tzframe(self): |
91 |
| - result = pd.DataFrame( |
92 |
| - { |
93 |
| - "A": pd.date_range("20130101", periods=3), |
94 |
| - "B": pd.date_range("20130101", periods=3, tz="US/Eastern"), |
95 |
| - "C": pd.date_range("20130101", periods=3, tz="CET"), |
96 |
| - } |
97 |
| - ) |
98 |
| - result.iloc[1, 1] = pd.NaT |
99 |
| - result.iloc[1, 2] = pd.NaT |
100 |
| - return result |
101 |
| - |
102 |
| - @cache_readonly |
103 |
| - def empty(self): |
104 |
| - return pd.DataFrame() |
105 |
| - |
106 |
| - @cache_readonly |
107 |
| - def ts1(self): |
108 |
| - return tm.makeTimeSeries(nper=30) |
109 |
| - |
110 |
| - @cache_readonly |
111 |
| - def ts2(self): |
112 |
| - return tm.makeTimeSeries(nper=30)[5:] |
113 |
| - |
114 |
| - @cache_readonly |
115 |
| - def simple(self): |
116 |
| - arr = np.array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]]) |
117 |
| - |
118 |
| - return pd.DataFrame(arr, columns=["one", "two", "three"], index=["a", "b", "c"]) |
119 |
| - |
120 |
| - |
121 |
| -# self.ts3 = tm.makeTimeSeries()[-5:] |
122 |
| -# self.ts4 = tm.makeTimeSeries()[1:-1] |
123 |
| - |
124 |
| - |
125 | 1 | def _check_mixed_float(df, dtype=None):
|
126 | 2 | # float16 are most likely to be upcasted to float32
|
127 | 3 | dtypes = dict(A="float32", B="float32", C="float16", D="float64")
|
|
0 commit comments