-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: Fix parsing of stata dates (#17797) #17990
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 4 commits
b5c2b48
bfd520d
16cfb87
b3273c4
04ec86f
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 |
---|---|---|
|
@@ -96,6 +96,8 @@ def setup_method(self, method): | |
|
||
self.dta24_111 = os.path.join(self.dirpath, 'stata7_111.dta') | ||
|
||
self.stata_dates = os.path.join(self.dirpath, 'stata13_dates.dta') | ||
|
||
def read_dta(self, file): | ||
# Legacy default reader configuration | ||
return read_stata(file, convert_dates=True) | ||
|
@@ -1327,3 +1329,22 @@ def test_set_index(self): | |
df.to_stata(path) | ||
reread = pd.read_stata(path, index_col='index') | ||
tm.assert_frame_equal(df, reread) | ||
|
||
@pytest.mark.parametrize( | ||
'column', ['ms', 'day', 'week', 'month', 'qtr', 'half', 'yr']) | ||
def test_date_parsing_ignores_format_details(self, column): | ||
# GH 17797 | ||
# | ||
# Test that display formats are ignored when determining if a numeric | ||
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. Nit: add a newline under the issue reference. |
||
# column is a date value. | ||
# | ||
# All date types are stored as numbers and format associated with the | ||
# column denotes both the type of the date and the display format. | ||
# | ||
# STATA supports 9 date types which each have distinct units. We test 7 | ||
# of the 9 types, ignoring %tC and %tb. %tC is a variant of %tc that | ||
# accounts for leap seconds and %tb relies on STATAs business calendar. | ||
df = read_stata(self.stata_dates) | ||
unformatted = df.loc[0, column] | ||
formatted = df.loc[0, column + "_fmt"] | ||
assert unformatted == formatted | ||
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. are these supposed to be what happens for the ignored formats? should raise? 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.
At this point in the code
Ignored formats are not converted to dates (consistent with previous behavior) source |
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 do
class:`~pandas.io.stata.StataReader`
. Can you make a bit more clear what is being fixed here.