Skip to content

Commit 3bf4bfd

Browse files
committed
Merge pull request #8699 from jreback/cbd
BUG: incorrect serialization of a CustomBusinessDay in HDF5 (GH8591)
2 parents fb124fd + 9d286c8 commit 3bf4bfd

File tree

4 files changed

+38
-10
lines changed

4 files changed

+38
-10
lines changed

doc/source/whatsnew/v0.15.1.txt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
.. _whatsnew_0151:
22

3-
v0.15.1 (November ??, 2014)
4-
-----------------------
3+
v0.15.1 (November 8, 2014)
4+
--------------------------
55

6-
This is a minor release from 0.15.0 and includes a small number of API changes, several new features,
6+
This is a minor bug-fix release from 0.15.0 and includes a small number of API changes, several new features,
77
enhancements, and performance improvements along with a large number of bug fixes. We recommend that all
88
users upgrade to this version.
99

10-
- Highlights include:
11-
1210
- :ref:`Enhancements <whatsnew_0151.enhancements>`
1311
- :ref:`API Changes <whatsnew_0151.api>`
1412
- :ref:`Performance Improvements <whatsnew_0151.performance>`
@@ -30,10 +28,10 @@ API changes
3028

3129
.. code-block:: python
3230

33-
# this was underreported and actually took (in < 0.15.1) about 24008 bytes
31+
# this was underreported in prior versions
3432
In [1]: dfi.memory_usage(index=True)
3533
Out[1]:
36-
Index 8000
34+
Index 8000 # took about 24008 bytes in < 0.15.1
3735
A 8000
3836
dtype: int64
3937

@@ -178,7 +176,7 @@ Experimental
178176
Bug Fixes
179177
~~~~~~~~~
180178

181-
179+
- Bug in unpickling of a ``CustomBusinessDay`` object (:issue:`8591`)
182180
- Bug in coercing ``Categorical`` to a records array, e.g. ``df.to_records()`` (:issue:`8626`)
183181
- Bug in ``Categorical`` not created properly with ``Series.to_frame()`` (:issue:`8626`)
184182
- Bug in coercing in astype of a ``Categorical`` of a passed ``pd.Categorical`` (this now raises ``TypeError`` correctly), (:issue:`8626`)

pandas/io/tests/test_pytables.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2047,6 +2047,28 @@ def compare(a,b):
20472047
result = store.select('df')
20482048
assert_frame_equal(result,df)
20492049

2050+
def test_calendar_roundtrip_issue(self):
2051+
2052+
# 8591
2053+
# doc example from tseries holiday section
2054+
weekmask_egypt = 'Sun Mon Tue Wed Thu'
2055+
holidays = ['2012-05-01', datetime.datetime(2013, 5, 1), np.datetime64('2014-05-01')]
2056+
bday_egypt = pandas.offsets.CustomBusinessDay(holidays=holidays, weekmask=weekmask_egypt)
2057+
dt = datetime.datetime(2013, 4, 30)
2058+
dts = date_range(dt, periods=5, freq=bday_egypt)
2059+
2060+
s = (Series(dts.weekday, dts).map(Series('Mon Tue Wed Thu Fri Sat Sun'.split())))
2061+
2062+
with ensure_clean_store(self.path) as store:
2063+
2064+
store.put('fixed',s)
2065+
result = store.select('fixed')
2066+
assert_series_equal(result, s)
2067+
2068+
store.append('table',s)
2069+
result = store.select('table')
2070+
assert_series_equal(result, s)
2071+
20502072
def test_append_with_timezones_dateutil(self):
20512073

20522074
from datetime import timedelta

pandas/tseries/offsets.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,14 @@ def __getstate__(self):
614614
"""Return a pickleable state"""
615615
state = self.__dict__.copy()
616616
del state['calendar']
617+
618+
# we don't want to actually pickle the calendar object
619+
# as its a np.busyday; we recreate on deserilization
620+
try:
621+
state['kwds'].pop('calendar')
622+
except:
623+
pass
624+
617625
return state
618626

619627
def __setstate__(self, state):

pandas/tseries/tests/test_offsets.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@
1212
from pandas.core.datetools import (
1313
bday, BDay, CDay, BQuarterEnd, BMonthEnd,
1414
CBMonthEnd, CBMonthBegin,
15-
BYearEnd, MonthEnd, MonthBegin, BYearBegin,
15+
BYearEnd, MonthEnd, MonthBegin, BYearBegin, CustomBusinessDay,
1616
QuarterBegin, BQuarterBegin, BMonthBegin, DateOffset, Week,
1717
YearBegin, YearEnd, Hour, Minute, Second, Day, Micro, Milli, Nano, Easter,
1818
WeekOfMonth, format, ole2datetime, QuarterEnd, to_datetime, normalize_date,
1919
get_offset, get_offset_name, get_standard_freq)
2020

21+
from pandas import Series
2122
from pandas.tseries.frequencies import _offset_map
2223
from pandas.tseries.index import _to_m8, DatetimeIndex, _daterange_cache, date_range
2324
from pandas.tseries.tools import parse_time_string
@@ -867,7 +868,6 @@ def test_pickle_compat_0_14_1(self):
867868
cday = CDay(holidays=hdays)
868869
self.assertEqual(cday, cday0_14_1)
869870

870-
871871
class CustomBusinessMonthBase(object):
872872
_multiprocess_can_split_ = True
873873

0 commit comments

Comments
 (0)