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

docs : docstrings examples - dtypes #1121

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

anopsy
Copy link
Member

@anopsy anopsy commented Oct 3, 2024

Just a quick check: considering I'll have to use cast to get some of the datatypes, maybe I should wrap the from_native into a func after all?

What type of PR is this? (check all applicable)

  • 💾 Refactor
  • ✨ Feature
  • 🐛 Bug Fix
  • 🔧 Optimization
  • 📝 Documentation
  • ✅ Test
  • 🐳 Other

Related issues

Checklist

  • Code follows style guide (ruff)
  • Tests added
  • Documented the changes

If you have comments or can explain your changes, please do so below.

@anopsy anopsy changed the title [docs] : docstrings examples for Int64 and Float64 dtypes docs : docstrings examples for Int64 and Float64 dtypes Oct 3, 2024
@github-actions github-actions bot added the documentation Improvements or additions to documentation label Oct 3, 2024
@anopsy anopsy changed the title docs : docstrings examples for Int64 and Float64 dtypes docs : docstrings examples - dtypes Oct 5, 2024
Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

thanks @anopsy !

for Categorical, it looks like casting from string is unsupported in old pyarrow versions* - but you can create the categorical directly:

>>> ca = pa.chunked_array(pa.array(['a', 'b'], type=pa.dictionary(pa.uint32(), pa.string())))
>>> nw.from_native(ca, series_only=True)
┌─────────────────────────────────────────┐
| Narwhals Series                         |
| Use `.to_native()` to see native output |
└─────────────────────────────────────────┘
>>> nw.from_native(ca, series_only=True).dtype
Categorical

For Struct / List / Array, there is a way to do that in pandas too use pd.ArrowDtype:

In [11]: pd.Series(data, dtype=pd.ArrowDtype(pa.large_list(pa.large_string())))
Out[11]:
0      ['narwhal' 'orca']
1    ['beluga' 'vaquita']
dtype: large_list<item: large_string>[pyarrow]

Similarly, for the struct example, I think you could use

pa.struct({'a': pa.int64(), 'b': pa.large_list(pa.large_string())})

*maybe we should only run doctests on the latest versions...that would save us a lot of # doctest: +SKIPs which would be a good thing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants