Skip to content

Commit 4490249

Browse files
committed
TST/BUG: Make sure locales are properly tested
1 parent 6ee748e commit 4490249

File tree

6 files changed

+42
-21
lines changed

6 files changed

+42
-21
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ python:
66
matrix:
77
include:
88
- python: 2.6
9-
env: NOSE_ARGS="not slow" CLIPBOARD=xclip
9+
env: NOSE_ARGS="not slow" CLIPBOARD=xclip LOCALE_OVERRIDE="it_IT.UTF-8"
1010
- python: 2.7
1111
env: NOSE_ARGS="slow and not network" LOCALE_OVERRIDE="zh_CN.GB18030" FULL_DEPS=true JOB_TAG=_LOCALE
1212
- python: 2.7

ci/install.sh

+15
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@
1313
# (no compiling needed), then directly goto script and collect 200$.
1414
#
1515

16+
function edit_init() {
17+
if [ -n "$LOCALE_OVERRIDE" ]; then
18+
pandas_dir=pandas
19+
echo "Adding locale to the first line of $pandas_dir/__init__.py"
20+
rm -f $pandas_dir/__init__.pyc
21+
sedc="1iimport locale; locale.setlocale(locale.LC_ALL, '$LOCALE_OVERRIDE')"
22+
sed -i "$sedc" $pandas_dir/__init__.py
23+
echo "First line of $pandas_dir/__init__.py"
24+
head $pandas_dir/__init__.py
25+
fi
26+
}
27+
1628
echo "inside $0"
1729

1830
# Install Dependencies
@@ -67,6 +79,9 @@ if [ x"$FULL_DEPS" == x"true" ]; then
6779
time sudo apt-get $APT_ARGS install libhdf5-serial-dev
6880
fi
6981

82+
83+
edit_init
84+
7085
# build pandas
7186
time python setup.py build_ext install
7287

ci/script.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ echo "inside $0"
55
if [ -n "$LOCALE_OVERRIDE" ]; then
66
export LC_ALL="$LOCALE_OVERRIDE";
77
echo "Setting LC_ALL to $LOCALE_OVERRIDE"
8-
(cd /; python -c 'import pandas; print("pandas detected console encoding: %s" % pandas.get_option("display.encoding"))')
9-
8+
pycmd='import pandas; print("pandas detected console encoding: %s" % pandas.get_option("display.encoding"))'
9+
python -c "$pycmd"
1010
fi
1111

1212
echo nosetests --exe -w /tmp -A "$NOSE_ARGS" pandas --show-skipped

pandas/tseries/converter.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from matplotlib.ticker import Formatter, AutoLocator, Locator
1111
from matplotlib.transforms import nonsingular
1212

13-
from pandas.compat import range, lrange
13+
from pandas.compat import lrange
1414
import pandas.compat as compat
1515
import pandas.lib as lib
1616
import pandas.core.common as com

pandas/tseries/tests/test_plotting.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,8 @@ def _test(ax):
317317
result = ax.get_xlim()
318318
self.assertEqual(int(result[0]), expected[0].ordinal)
319319
self.assertEqual(int(result[1]), expected[1].ordinal)
320-
plt.close(ax.get_figure())
320+
fig = ax.get_figure()
321+
plt.close(fig)
321322

322323
ser = tm.makeTimeSeries()
323324
ax = ser.plot()

pandas/tslib.pyx

+21-16
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ from datetime import timedelta, datetime
3535
from datetime import time as datetime_time
3636
from pandas.compat import parse_date
3737

38+
from sys import version_info
39+
40+
# GH3363
41+
cdef bint PY2 = version_info[0] == 2
42+
3843
# initialize numpy
3944
import_array()
4045
#import_ufunc()
@@ -1757,20 +1762,20 @@ def tz_localize_to_utc(ndarray[int64_t] vals, object tz, bint infer_dst=False):
17571762
# timestamp falls to the right side of the DST transition
17581763
if v + deltas[pos] == vals[i]:
17591764
result_b[i] = v
1760-
1761-
1765+
1766+
17621767
if infer_dst:
17631768
dst_hours = np.empty(n, dtype=np.int64)
17641769
dst_hours.fill(NPY_NAT)
1765-
1770+
17661771
# Get the ambiguous hours (given the above, these are the hours
1767-
# where result_a != result_b and neither of them are NAT)
1772+
# where result_a != result_b and neither of them are NAT)
17681773
both_nat = np.logical_and(result_a != NPY_NAT, result_b != NPY_NAT)
17691774
both_eq = result_a == result_b
17701775
trans_idx = np.squeeze(np.nonzero(np.logical_and(both_nat, ~both_eq)))
17711776
if trans_idx.size == 1:
17721777
stamp = Timestamp(vals[trans_idx])
1773-
raise pytz.AmbiguousTimeError("Cannot infer dst time from %s as"
1778+
raise pytz.AmbiguousTimeError("Cannot infer dst time from %s as"
17741779
"there are no repeated times" % stamp)
17751780
# Split the array into contiguous chunks (where the difference between
17761781
# indices is 1). These are effectively dst transitions in different years
@@ -1779,21 +1784,21 @@ def tz_localize_to_utc(ndarray[int64_t] vals, object tz, bint infer_dst=False):
17791784
if trans_idx.size > 0:
17801785
one_diff = np.where(np.diff(trans_idx)!=1)[0]+1
17811786
trans_grp = np.array_split(trans_idx, one_diff)
1782-
1787+
17831788
# Iterate through each day, if there are no hours where the delta is negative
17841789
# (indicates a repeat of hour) the switch cannot be inferred
17851790
for grp in trans_grp:
1786-
1791+
17871792
delta = np.diff(result_a[grp])
17881793
if grp.size == 1 or np.all(delta>0):
17891794
stamp = Timestamp(vals[grp[0]])
17901795
raise pytz.AmbiguousTimeError(stamp)
1791-
1796+
17921797
# Find the index for the switch and pull from a for dst and b for standard
17931798
switch_idx = (delta<=0).nonzero()[0]
17941799
if switch_idx.size > 1:
17951800
raise pytz.AmbiguousTimeError("There are %i dst switches "
1796-
"when there should only be 1."
1801+
"when there should only be 1."
17971802
% switch_idx.size)
17981803
switch_idx = switch_idx[0]+1 # Pull the only index and adjust
17991804
a_idx = grp[:switch_idx]
@@ -1812,7 +1817,7 @@ def tz_localize_to_utc(ndarray[int64_t] vals, object tz, bint infer_dst=False):
18121817
else:
18131818
stamp = Timestamp(vals[i])
18141819
raise pytz.AmbiguousTimeError("Cannot infer dst time from %r, "\
1815-
"try using the 'infer_dst' argument"
1820+
"try using the 'infer_dst' argument"
18161821
% stamp)
18171822
elif left != NPY_NAT:
18181823
result[i] = left
@@ -2549,8 +2554,9 @@ cdef list extra_fmts = [(b"%q", b"^`AB`^"),
25492554

25502555
cdef list str_extra_fmts = ["^`AB`^", "^`CD`^", "^`EF`^", "^`GH`^", "^`IJ`^", "^`KL`^"]
25512556

2552-
cdef _period_strftime(int64_t value, int freq, object fmt):
2557+
cdef object _period_strftime(int64_t value, int freq, object fmt):
25532558
import sys
2559+
25542560
cdef:
25552561
Py_ssize_t i
25562562
date_info dinfo
@@ -2596,12 +2602,11 @@ cdef _period_strftime(int64_t value, int freq, object fmt):
25962602
result = result.replace(str_extra_fmts[i], repl)
25972603

25982604
# Py3?
2599-
if not PyString_Check(result):
2600-
result = str(result)
2605+
#if not PyString_Check(result):
2606+
#result = str(result)
26012607

2602-
# GH3363
2603-
if sys.version_info[0] == 2:
2604-
result = result.decode('utf-8','strict')
2608+
if PY2:
2609+
result = result.decode('utf-8', 'ignore')
26052610

26062611
return result
26072612

0 commit comments

Comments
 (0)