Skip to content

Commit 5491fb6

Browse files
committed
DEPR: rename Timestamp.offset to .freq
1 parent 1edc1df commit 5491fb6

19 files changed

+140
-90
lines changed

doc/source/whatsnew/v0.19.0.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ Deprecations
439439
- ``buffer_lines`` has been deprecated in ``pd.read_csv()`` and will be removed in a future version (:issue:`13360`)
440440
- ``as_recarray`` has been deprecated in ``pd.read_csv()`` and will be removed in a future version (:issue:`13373`)
441441
- top-level ``pd.ordered_merge()`` has been renamed to ``pd.merge_ordered()`` and the original name will be removed in a future version (:issue:`13358`)
442+
- ``Timestamp`` ``offset`` option and property has been deprecated in favor of ``freq`` (:issue:`12160`)
442443

443444
.. _whatsnew_0190.performance:
444445

pandas/io/packers.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -481,12 +481,12 @@ def encode(obj):
481481
tz = obj.tzinfo
482482
if tz is not None:
483483
tz = u(tz.zone)
484-
offset = obj.offset
485-
if offset is not None:
486-
offset = u(offset.freqstr)
484+
freq = obj.freq
485+
if freq is not None:
486+
freq = u(freq.freqstr)
487487
return {u'typ': u'timestamp',
488488
u'value': obj.value,
489-
u'offset': offset,
489+
u'freq': freq,
490490
u'tz': tz}
491491
if isinstance(obj, NaTType):
492492
return {u'typ': u'nat'}
@@ -556,7 +556,8 @@ def decode(obj):
556556
if typ is None:
557557
return obj
558558
elif typ == u'timestamp':
559-
return Timestamp(obj[u'value'], tz=obj[u'tz'], offset=obj[u'offset'])
559+
freq = obj[u'freq'] if 'freq' in obj else obj[u'offset']
560+
return Timestamp(obj[u'value'], tz=obj[u'tz'], freq=freq)
560561
elif typ == u'nat':
561562
return NaT
562563
elif typ == u'period':
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

pandas/io/tests/generate_legacy_storage_files.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
SparseSeries, SparseDataFrame,
66
Index, MultiIndex, bdate_range, to_msgpack,
77
date_range, period_range,
8-
Timestamp, Categorical, Period)
8+
Timestamp, NaT, Categorical, Period)
99
from pandas.compat import u
1010
import os
1111
import sys
@@ -140,6 +140,13 @@ def create_data():
140140
int16=Categorical(np.arange(1000)),
141141
int32=Categorical(np.arange(10000)))
142142

143+
timestamp = dict(normal=Timestamp('2011-01-01'),
144+
nat=NaT,
145+
tz=Timestamp('2011-01-01', tz='US/Eastern'),
146+
freq=Timestamp('2011-01-01', offset='D'),
147+
both=Timestamp('2011-01-01', tz='Asia/Tokyo',
148+
offset='M'))
149+
143150
return dict(series=series,
144151
frame=frame,
145152
panel=panel,
@@ -149,7 +156,8 @@ def create_data():
149156
sp_series=dict(float=_create_sp_series(),
150157
ts=_create_sp_tsseries()),
151158
sp_frame=dict(float=_create_sp_frame()),
152-
cat=cat)
159+
cat=cat,
160+
timestamp=timestamp)
153161

154162

155163
def create_pickle_data():

pandas/io/tests/test_packers.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from distutils.version import LooseVersion
99

1010
from pandas import compat
11-
from pandas.compat import u
11+
from pandas.compat import u, PY3
1212
from pandas import (Series, DataFrame, Panel, MultiIndex, bdate_range,
1313
date_range, period_range, Index, Categorical)
1414
from pandas.core.common import PerformanceWarning
@@ -58,6 +58,19 @@ def check_arbitrary(a, b):
5858
assert_series_equal(a, b)
5959
elif isinstance(a, Index):
6060
assert_index_equal(a, b)
61+
elif isinstance(a, Categorical):
62+
# Temp,
63+
# Categorical.categories is changed from str to bytes in PY3
64+
# maybe the same as GH 13591
65+
if PY3 and b.categories.inferred_type == 'string':
66+
pass
67+
else:
68+
tm.assert_categorical_equal(a, b)
69+
elif a is NaT:
70+
tm.assertIs(b, NaT)
71+
elif isinstance(a, Timestamp):
72+
assert a == b
73+
assert a.freq == b.freq
6174
else:
6275
assert(a == b)
6376

@@ -815,8 +828,8 @@ def check_min_structure(self, data):
815828
for typ, v in self.minimum_structure.items():
816829
assert typ in data, '"{0}" not found in unpacked data'.format(typ)
817830
for kind in v:
818-
assert kind in data[
819-
typ], '"{0}" not found in data["{1}"]'.format(kind, typ)
831+
msg = '"{0}" not found in data["{1}"]'.format(kind, typ)
832+
assert kind in data[typ], msg
820833

821834
def compare(self, vf, version):
822835
# GH12277 encoding default used to be latin-1, now utf-8
@@ -839,8 +852,8 @@ def compare(self, vf, version):
839852

840853
# use a specific comparator
841854
# if available
842-
comparator = getattr(
843-
self, "compare_{typ}_{dt}".format(typ=typ, dt=dt), None)
855+
comp_method = "compare_{typ}_{dt}".format(typ=typ, dt=dt)
856+
comparator = getattr(self, comp_method, None)
844857
if comparator is not None:
845858
comparator(result, expected, typ, version)
846859
else:
@@ -872,9 +885,8 @@ def read_msgpacks(self, version):
872885
n = 0
873886
for f in os.listdir(pth):
874887
# GH12142 0.17 files packed in P2 can't be read in P3
875-
if (compat.PY3 and
876-
version.startswith('0.17.') and
877-
f.split('.')[-4][-1] == '2'):
888+
if (compat.PY3 and version.startswith('0.17.') and
889+
f.split('.')[-4][-1] == '2'):
878890
continue
879891
vf = os.path.join(pth, f)
880892
try:

pandas/io/tests/test_pickle.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ def compare_element(self, result, expected, typ, version=None):
4646
if typ.startswith('sp_'):
4747
comparator = getattr(tm, "assert_%s_equal" % typ)
4848
comparator(result, expected, exact_indices=False)
49+
elif typ == 'timestamp':
50+
if expected is pd.NaT:
51+
assert result is pd.NaT
52+
else:
53+
tm.assert_equal(result, expected)
54+
tm.assert_equal(result.freq, expected.freq)
4955
else:
5056
comparator = getattr(tm, "assert_%s_equal" %
5157
typ, tm.assert_almost_equal)

pandas/lib.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# prototypes for sharing
22

33
cdef bint is_null_datetimelike(v)
4+
cpdef bint is_period(val)

0 commit comments

Comments
 (0)