-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
API/COMPAT: add pydatetime-style positional args to Timestamp constructor #12482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0d6884b
5c34c04
6fad30b
9c1e2dc
a334eab
0ac786f
79d63d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -180,6 +180,52 @@ def test_constructor_invalid(self): | |
with tm.assertRaisesRegexp(ValueError, 'Cannot convert Period'): | ||
Timestamp(Period('1000-01-01')) | ||
|
||
def test_constructor_positional(self): | ||
# GH 10758 | ||
with tm.assertRaises(TypeError): | ||
Timestamp(2000, 1) | ||
with tm.assertRaises(ValueError): | ||
Timestamp(2000, 0, 1) | ||
with tm.assertRaises(ValueError): | ||
Timestamp(2000, 13, 1) | ||
with tm.assertRaises(ValueError): | ||
Timestamp(2000, 1, 0) | ||
with tm.assertRaises(ValueError): | ||
Timestamp(2000, 1, 32) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add some tests where |
||
# GH 11630 | ||
self.assertEqual( | ||
repr(Timestamp(2015, 11, 12)), | ||
repr(Timestamp('20151112'))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is the test for #11630, Github didn't do the best job linking it to your earlier comment. |
||
|
||
self.assertEqual( | ||
repr(Timestamp(2015, 11, 12, 1, 2, 3, 999999)), | ||
repr(Timestamp('2015-11-12 01:02:03.999999'))) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you add the assertion for |
||
self.assertIs(Timestamp(None), pd.NaT) | ||
|
||
def test_constructor_keyword(self): | ||
# GH 10758 | ||
with tm.assertRaises(TypeError): | ||
Timestamp(year=2000, month=1) | ||
with tm.assertRaises(ValueError): | ||
Timestamp(year=2000, month=0, day=1) | ||
with tm.assertRaises(ValueError): | ||
Timestamp(year=2000, month=13, day=1) | ||
with tm.assertRaises(ValueError): | ||
Timestamp(year=2000, month=1, day=0) | ||
with tm.assertRaises(ValueError): | ||
Timestamp(year=2000, month=1, day=32) | ||
|
||
self.assertEqual( | ||
repr(Timestamp(year=2015, month=11, day=12)), | ||
repr(Timestamp('20151112'))) | ||
|
||
self.assertEqual( | ||
repr(Timestamp(year=2015, month=11, day=12, | ||
hour=1, minute=2, second=3, microsecond=999999)), | ||
repr(Timestamp('2015-11-12 01:02:03.999999'))) | ||
|
||
def test_conversion(self): | ||
# GH 9255 | ||
ts = Timestamp('2000-01-01') | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you use
assertRaisesRegexp
here to check for thingsdoesn't have to be an exact checking, but need to make sure that it is raising the
datetime.datetime
constructor error message and not something else.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the cases where not enough parameters are passed to
Timestamp
, the error will bean integer is required (got NoneType)
instead ofRequired argument not found
. Matching thedatetime
exception exactly requires 3 additional checks and calls:which seems ugly. Do we really want that?