Skip to content
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

fix: datetime.data in series #20618

Merged
merged 1 commit into from
Jul 7, 2022

Conversation

zhaoyongjie
Copy link
Member

@zhaoyongjie zhaoyongjie commented Jul 6, 2022

Background

the pd.api.types.is_datetime64_any_dtype(series) is not able to check a series that contains datetime.date, the dtype of the dataframe will be object e.g.:

>>> import datetime
>>> import pandas as pd

>>> series = pd.Series([datetime.date(2018, 1, 1), datetime.date(2018, 1, 2)])
>>> pd.api.types.is_datetime64_any_dtype(series)
False
>>> series
0    2018-01-01
1    2018-01-02
dtype: object

if a series is a DateTime series, the pd.api.types.is_datetime64_any_dtype(series) will correctly check dtype.

>>> import datetime
>>> import pandas as pd

>>> series = pd.Series([datetime.datetime(2018, 1, 1), datetime.datetime(2018, 1, 2)])
>>> pd.api.types.is_datetime64_any_dtype(series)
True
>>> series
0    2018-01-01
1    2018-01-02
dtype: datetime64[ns]

Solution

add a new function is_datetime_series to only check series type instead of dtype.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

date.type.in.series.mov

TESTING INSTRUCTIONS

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@codecov
Copy link

codecov bot commented Jul 6, 2022

Codecov Report

Merging #20618 (4ae05e5) into master (818962c) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master   #20618   +/-   ##
=======================================
  Coverage   66.82%   66.82%           
=======================================
  Files        1752     1752           
  Lines       65609    65616    +7     
  Branches     6938     6938           
=======================================
+ Hits        43842    43849    +7     
  Misses      20007    20007           
  Partials     1760     1760           
Flag Coverage Δ
hive 53.80% <41.66%> (-0.01%) ⬇️
mysql 82.38% <100.00%> (+<0.01%) ⬆️
postgres 82.45% <100.00%> (+<0.01%) ⬆️
presto 53.67% <41.66%> (-0.01%) ⬇️
python 82.89% <100.00%> (+<0.01%) ⬆️
sqlite 82.24% <100.00%> (+<0.01%) ⬆️
unit 50.69% <75.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
superset/common/query_context_processor.py 90.27% <100.00%> (ø)
superset/common/utils/dataframe_utils.py 95.23% <100.00%> (+2.38%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 818962c...4ae05e5. Read the comment docs.

Copy link
Member

@john-bodley john-bodley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a shame that Pandas doesn't have native support for datetime.date objects. Maybe this is yet another reason we should eventually replace it with PyArrow.

@zhaoyongjie
Copy link
Member Author

Thanks, @john-bodley! I am impressed with the Arrow zero-copy feature.

@zhaoyongjie zhaoyongjie merged commit 414cc99 into apache:master Jul 7, 2022
jinghua-qa pushed a commit to preset-io/superset that referenced this pull request Jul 8, 2022
jinghua-qa pushed a commit to preset-io/superset that referenced this pull request Jul 12, 2022
jinghua-qa pushed a commit to preset-io/superset that referenced this pull request Jul 12, 2022
akshatsri pushed a commit to charan1314/superset that referenced this pull request Jul 19, 2022
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 2.1.0 labels Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels preset:2022.27 size/M 🚢 2.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants