sassoftware / sassoftware/python-swat

applying formats using fetch or to_frame makes all DataFrame columns objects

Open
#147 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
159
Forks
65
PR merge metrics
No merged PRs in 30d

Description

If you have formats on only a few columns in a CAS table and try to apply the formats to the SASDataFrame, the swat package converts all columns to objects, even if the column is a simple number.

For example:

Packages

import swat
import pandas as pd

Connect to CAS

conn = ##connection info

load data to CAS

data = r'https://support.sas.com/documentation/onlinedoc/viya/exampledatasets/cars.csv'
tbl = conn.upload_file(data,
casout = {'name':'cars_upload', 'caslib':'casuser','replace':True},
importoptions={
'stripBlanks':True,
'guessRows':200,
'vars':{
'MSRP':{'format':'dollar16.'},
'Weight':{'format':'comma16.'}
}})

Only the MSRP and Weight columns have a format

tbl.columnInfo()

image

Pull the CAS table to the client as a SASDataFrame and apply the formats. This works as expected

df = tbl.to_frame(format=True)
df.head()

image

View the data types of the SASDataFrame

image

Everything turns into an object. It seems like only the formatted columns should be converted. Numeric columns without formats should remain numbers.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the behavior with tbl.to_frame(format=True) using the cars example and inspect the resulting SASDataFrame dtypes. Trace the formatting path used by to_frame or fetch, then add coverage showing that only formatted columns become objects while unformatted numeric columns retain numeric types.

Written by the indexing model from the issue text.

Assessment

Tech stack
pandas, python
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.