summary refs log tree commit diff
path: root/gnu/packages/patches/python-pandas-fix-tslib-test-failure.patch
blob: 62d6a38086500345c5c9c3d14beb62567e8b09fc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
This patch is required to fix a test failure when python-dateutil version
2.5.2 or later is used.  It is derived from the following commits:

80ef4e06526b9b60cf24268454c9456585a790a3
845ff974af6f7c3b3067cce8a7149b771c2be87

diff --git a/pandas/tseries/tests/test_tslib.py b/pandas/tseries/tests/test_tslib.py
index f0d5bf7..863bc6f 100644
--- a/pandas/tseries/tests/test_tslib.py
+++ b/pandas/tseries/tests/test_tslib.py
@@ -474,6 +474,11 @@ def test_does_not_convert_mixed_integer(self):
                 good_date_string))
 
     def test_parsers(self):
+
+        # https://github.com/dateutil/dateutil/issues/217
+        import dateutil
+        yearfirst = dateutil.__version__ >= LooseVersion('2.5.0')
+
         cases = {'2011-01-01': datetime.datetime(2011, 1, 1),
                  '2Q2005': datetime.datetime(2005, 4, 1),
                  '2Q05': datetime.datetime(2005, 4, 1),
@@ -527,20 +532,26 @@ def test_parsers(self):
                  }
 
         for date_str, expected in compat.iteritems(cases):
-            result1, _, _ = tools.parse_time_string(date_str)
-            result2 = to_datetime(date_str)
-            result3 = to_datetime([date_str])
-            result4 = to_datetime(np.array([date_str], dtype=object))
-            result5 = Timestamp(date_str)
-            result6 = DatetimeIndex([date_str])[0]
-            result7 = date_range(date_str, freq='S', periods=1)
+            result1, _, _ = tools.parse_time_string(date_str,
+                                                    yearfirst=yearfirst)
+            result2 = to_datetime(date_str, yearfirst=yearfirst)
+            result3 = to_datetime([date_str], yearfirst=yearfirst)
+            result4 = to_datetime(np.array([date_str], dtype=object),
+                                  yearfirst=yearfirst)
+            result6 = DatetimeIndex([date_str], yearfirst=yearfirst)[0]
             self.assertEqual(result1, expected)
             self.assertEqual(result2, expected)
             self.assertEqual(result3, expected)
             self.assertEqual(result4, expected)
-            self.assertEqual(result5, expected)
             self.assertEqual(result6, expected)
-            self.assertEqual(result7, expected)
+
+            # these really need to have yearfist, but we don't support
+            if not yearfirst:
+                result5 = Timestamp(date_str)
+                self.assertEqual(result5, expected)
+                result7 = date_range(date_str, freq='S', periods=1,
+                                     yearfirst=yearfirst)
+                self.assertEqual(result7, expected)
 
         # NaT
         result1, _, _ = tools.parse_time_string('NaT')
@@ -589,23 +589,62 @@ def test_parsers_quarter_invalid(self):
             self.assertRaises(ValueError, tools.parse_time_string, case)
 
     def test_parsers_dayfirst_yearfirst(self):
+
+        # https://github.com/dateutil/dateutil/issues/217
+        # this issue was closed
+        import dateutil
+        is_compat_version = dateutil.__version__ >= LooseVersion('2.5.2')
+        if is_compat_version:
+            dayfirst_yearfirst1 = datetime.datetime(2010, 12, 11)
+            dayfirst_yearfirst2 = datetime.datetime(2020, 12, 21)
+        else:
+            dayfirst_yearfirst1 = datetime.datetime(2010, 11, 12)
+            dayfirst_yearfirst2 = datetime.datetime(2020, 12, 21)
+
         # str : dayfirst, yearfirst, expected
-        cases = {'10-11-12': [(False, False, datetime.datetime(2012, 10, 11)),
-                              (True, False, datetime.datetime(2012, 11, 10)),
-                              (False, True, datetime.datetime(2010, 11, 12)),
-                              (True, True, datetime.datetime(2010, 11, 12))],
-                 '20/12/21': [(False, False, datetime.datetime(2021, 12, 20)),
-                              (True, False, datetime.datetime(2021, 12, 20)),
-                              (False, True, datetime.datetime(2020, 12, 21)),
-                              (True, True, datetime.datetime(2020, 12, 21))]}
+        cases = {'10-11-12': [(False, False, False,
+                               datetime.datetime(2012, 10, 11)),
+                              (True, False, False,
+                               datetime.datetime(2012, 11, 10)),
+                              (False, True, False,
+                               datetime.datetime(2010, 11, 12)),
+                              (True, True, False, dayfirst_yearfirst1)],
+                 '20/12/21': [(False, False, False,
+                               datetime.datetime(2021, 12, 20)),
+                              (True, False, False,
+                               datetime.datetime(2021, 12, 20)),
+                              (False, True, False,
+                               datetime.datetime(2020, 12, 21)),
+                              (True, True, True, dayfirst_yearfirst2)]}
 
         tm._skip_if_no_dateutil()
         from dateutil.parser import parse
         for date_str, values in compat.iteritems(cases):
-            for dayfirst, yearfirst, expected in values:
-                result1, _, _ = tools.parse_time_string(date_str,
-                                                        dayfirst=dayfirst,
-                                                        yearfirst=yearfirst)
+            for dayfirst, yearfirst, is_compat, expected in values:
+
+                f = lambda x: tools.parse_time_string(x,
+                                                      dayfirst=dayfirst,
+                                                      yearfirst=yearfirst)
+
+                # we now have an invalid parse
+                if is_compat and is_compat_version:
+                    self.assertRaises(tslib.DateParseError, f, date_str)
+
+                    def f(date_str):
+                        return to_datetime(date_str, dayfirst=dayfirst,
+                                           yearfirst=yearfirst)
+
+                    self.assertRaises(ValueError, f, date_str)
+
+                    def f(date_str):
+                        return DatetimeIndex([date_str], dayfirst=dayfirst,
+                                             yearfirst=yearfirst)[0]
+
+                    self.assertRaises(ValueError, f, date_str)
+
+                    continue
+
+                result1, _, _ = f(date_str)
 
                 result2 = to_datetime(date_str, dayfirst=dayfirst,
                                       yearfirst=yearfirst)
@@ -614,7 +653,6 @@ def test_parsers_dayfirst_yearfirst(self):
                                         yearfirst=yearfirst)[0]
 
                 # Timestamp doesn't support dayfirst and yearfirst
-
                 self.assertEqual(result1, expected)
                 self.assertEqual(result2, expected)
                 self.assertEqual(result3, expected)